我正在用Php an Angular構建一個項目,我可以將文件上傳到本地數據庫,並且可以檢索文件信息。我不知道如何檢索文件本身並將其下載到我的電腦。有人可以幫忙嗎? 在數據庫 - 柱/類型= ID-INT,名稱VARCHAR,MIME-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>
Your將文件存儲在數據庫中的blob元素? –
@GeeK是不是很好?對不起,我是新來的...你有什麼建議? – tanyaa
我希望我的回答有幫助,如果您需要更多詳細信息,請告知我。 –