[英]how to download uploaded files?
I'm building a project with Php an Angular, I can upload files to local database and I can retrieve files information. 我正在用Php Angular构建项目,可以将文件上传到本地数据库,也可以检索文件信息。 i don't know how to retrieve the file itself and download it to my computer.
我不知道如何检索文件本身并将其下载到我的计算机。 can someone please help?
有人可以帮忙吗? in database - column/type= id-int, name-varchar, mime-longblob, size-biginet, data-mediumblob, created-datetime
在数据库中-column / type = id-int,name-varchar,mime-longblob,size-biginet,data-mediumblob,created-datetime
Php for retrieving files details: 获取文件详细信息的PHP:
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);
controller: 控制器:
"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: 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>
A better solution is to upload the files to server and add a .htaccess to restrict access, rename the file to a serial number so two files with same name never override and store the path of the file inculding filename.extension (relative path from website), serialNo. 更好的解决方案是将文件上传到服务器并添加.htaccess来限制访问,将文件重命名为序列号,这样两个名称相同的文件就不会覆盖并存储包含filename.extension的文件的路径(来自网站的相对路径) ), 序列号。 as id and real-name of the file(with extension).
作为文件的ID和实名(带有扩展名)。 populate the path as required and rename before downloading.
根据需要填充路径,并在下载前重命名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.