当我从数据库下载文件然后“无法加载”消息显示

时间:2017-07-13 04:38:32

标签: php

我正在尝试从数据库下载文件。但它显示“无法加载”消息。上传工作正常。我可以上传pdf,jpg,dox文件。但是当我下载时无法打开。我的文件中有三个href链接。第一个用于“上传”第二个用于“删除”。每个链接从图像下载文件,甚至其他链接用于其他工作,但每个文件调用downld.php文件

<a href="downld.php?id=<?php echo $project_id;?>"><?php echo $name;?></a>


downld.php



<?php
if (isset($_GET['id']))
{
$project_id = $_GET['id'];
$myConnection= mysqli_connect("localhost","root","", "extra") or die ("could 
not connect to mysql");
mysqli_set_charset($myConnection,'utf-8');
global $wpdb;
$sql = "SELECT name, type, size, content " .
"FROM wp_postprojectwin WHERE project_id = $project_id";


$result = mysqli_query($myConnection,$sql) or die('Error, query failed');

list($name, $type, $size, $content) =  mysqli_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");

mysqli_close($connection);
ob_clean();
 flush();
echo $content;
exit;
}
else{

echo "sorry";


}

?>

0 个答案:

没有答案