我正在用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
我希望我的回答有帮助,如果您需要更多详细信息,请告知我。 –