【发布时间】:2011-08-12 01:00:49
【问题描述】:
这涉及使用 PHP 下载文件
我的php版本是5.3.5,我的apache是2.2.17
我正在尝试下载我在服务器中上传的文件(pdf、jpg、tiff),它们以相同的大小和类型下载,但我看不到它们。我猜他们没有被正确复制。但是当我打开原始上传的那些时,它们工作得很好。 我已经看到了几乎所有按照建议出现的问题,但没有一个人回答了这个问题,只有一个类似的问题是this,但仍然没有回答我的问题。
下载我正在使用此代码
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="' . $dir . '"');
header("Content-Transfer-Encoding: Binary");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-length: ".filesize($dir));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$dir");
$dir="62756d616769636e63/646973736572746174/ehddggh/1.JPG"
和$file="1.JPG"
谁能给我一个提示我做错了什么,或者给我一个更好的解决方案来下载文件?
【问题讨论】:
-
Content-type两次...Content-disposition两次... 第一个标头不会做任何事情(不会被发送)。还有filesize($dir)有点奇怪,你不觉得吗? dir 的 file 大小...