我正在尝试使用php从mysqli数据库下载文件,因为我已将文件存储在文件夹中,并且文件名存储在mysqli数据库中。
这是我的代码...
$query= mysqli_query($dbo,"SELECT * FROM diff_questions WHERE email = ' $email ' and status= '0' ");
$rows=mysqli_fetch_array($query);
$file=$rows['file'];
$path='http://localhost/admin1/uploads';
?>
echo "<a href='download.php?file=".$file."&path=".$path." '>Download File</a> ";
现在download.php-
<?php
$file = $_GET["file"];
$path = $_GET["path"];
$fullfile = $path.$file;
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . Urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . Filesize($fullfile));
flush();
$fp = fopen($fullfile, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush();
}
fclose($fp);
?>
有人可以告诉我代码有什么问题吗?它不起作用。我的意思是直到保存文件之前,它一直在工作,但是它没有下载完整文件,而文件的下载文件大小为0kb
将您的download.php替换为以下代码后,检查其是否对您有用:
if(isset($_GET["file"])){
$file = $_GET["file"];
$path = $_GET["path"];
$fullfile = $path.$file;
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . Urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
$fp = fopen($fullfile,'r');
while ($line = fgets($fp)) {
echo($line);
}
fclose($fp);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句