2016-08-02 9 views
0

PHP로 프로젝트를 만들고 있는데 로컬 데이터베이스에 파일을 업로드 할 수 있으며 파일 정보를 검색 할 수 있습니다. 파일 자체를 가져 와서 내 컴퓨터로 다운로드하는 방법을 모르겠습니다. 누군가 도와 주실 수 있습니까? 데이터베이스에 - 열/유형 = ID-INT, 이름 VARCHAR, 마임 LONGBLOB, 크기 biginet, 데이터 MEDIUMBLOB, 파일 정보를 검색하기위한 생성 - 날짜업로드 된 파일을 다운로드하는 방법?

빌을 :

header('Content-Type: text/html; charset=utf-8'); 

    $connection = mysqli_connect('localhost', 'root', '', 'hamatkin'); 

    mysqli_query($connection, "SET character_set_client = utf8"); 
    mysqli_query($connection, "SET character_set_connection = utf8"); 
    mysqli_query($connection, "SET character_set_results = utf8"); 

    if (!$connection) { 
    die("couldnt connect".mysqli_error); 
    } 

    $query = "SELECT id, name, created FROM file"; 
    $queryResult = $connection->query($query); 

    $queryResult2 = array(); 

    if ($queryResult === false) { 
    die($connection->error); 
    } 

    if ($queryResult->num_rows > 0) { 
    while ($row = $queryResult->fetch_assoc()) { 
     $queryResult2[] = $row; 
    } 
    } 

    $queryResult3 = json_encode($queryResult2); 

    echo json_encode($queryResult2); 

컨트롤러 :

"use strict";

angular.module('dataSystem').controller('allPriceOffersCtrl', function($scope,$route,$location,$http) { 
    $http({method:'GET', url:'api/customers-tab/get-all-priceOffers.php/'}) 
     .then(function(response) { 
     var arr = response.data; 
     $scope.files = arr; 
     }) 
     // This will log you the error code and trace, if there is an error. 
     .catch(function(err) { 
     console.log('err', err) 
     }); 

}); 

HTML :

<div class="table-responsive"> 
    <table class="customer-list table table-striped"> 
    <thead> 
     <tr> 
     <!-- <th>#</th> --> 
     <th class="Column-Header"> מספר קובץ הצעת מחיר</th> 
     <th class="Column-Header">שם הקובץ</th> 
     <th class="Column-Header">תאריך</th> 

     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="x in files "> 
     <!-- <td>{{$index + 1}}</td> --> 
     <td>{{ x.id}}</td> 
     <td>{{ x.name}}</td> 
     <td> {{ x.created}} </td> 
     </tr> 
    </tbody> 
    </table> 
</div> 
+0

데이터베이스에 파일을 BLOB 요소로 저장 하시겠습니까? –

+0

@ GeeK 그게 좋지 않아? 이걸로 내가 처음인데 미안해 ... 너 뭐라고 제안 하나? – tanyaa

+0

내 답변이 도움이되기를 바랍니다. 자세한 내용이 필요하면 알려주세요. –

답변

1

더 나은 솔루션이 같은 이름을 결코 오버라이드 그래서 두 개의 파일을 서버에 파일을 업로드하고 액세스를 제한 할 수있는 htaccess로를 추가, 일련 번호에 파일의 이름을 변경하는 것입니다 filename.extension (웹 사이트의 상대 경로), serialNo 등의 파일 경로를 저장합니다. 파일의 ID와 실제 이름 (확장자 포함). 필요에 따라 경로를 채우고 다운로드하기 전에 이름을 변경하십시오.

Example이 무엇이겠습니까

+0

정확히 무엇을 해야할지 이해하지 못해 죄송합니다 .... – tanyaa

+1

http://www.php-mysql-tutorial.com/wikis/php-tutorial/uploading-files-to-the-server-using -php.aspx 이 예제를 읽으십시오. 더 자세히 설명 하겠지만 여전히 이해할 수 없다면 데이터베이스 구조를 제공하고 직접 설명하겠습니다. –

+0

채팅 할 수 있습니까? – tanyaa

관련 문제