小编Ako*_*kos的帖子

header('Content-type:application/octet-stream')导致0字节文件

我在PHP中使用数据库查询来检索二进制文件.但是当我试图强制下载它时,标题('Content-type:application/octet-stream')行会导致0字节文件.如果没有该行,我可以下载包含完整内容的文件.这是一个肯定的二进制文件,所以我无法理解为什么该行会导致问题.代码:

$result = mysql_query("SELECT data FROM stored_file WHERE file_name = '$q'");

while($row = mysql_fetch_array($result))
{
    $file = $row['data'];
}


    header('Content-disposition: attachment; filename='.$q);
    header('Content-type: application/octet-stream');
    header('Content-Length: '.filesize($file));
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $file;
Run Code Online (Sandbox Code Playgroud)

任何的想法?谢谢.

php download

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

download ×1

php ×1