我有一个强制下载的 PHP 脚本。这是我的代码
//$file and $mime have been set earlier
$basename = basename($file);
$length = sprintf("%u", filesize($file));
header('Content-Description: File Transfer');
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="' . $basename . '"');
header('Content-Transfer-Encoding: Binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $length);
set_time_limit(0);
readfile($file);
现在这个脚本在我的本地服务器上完美运行,但是当我将它上传到我的站点并尝试它时,下载了文件(为了测试它我使用了一个图像),但是当我打开它时,我得到了Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or is too large.
我在 Sublime Text 中打开了文件,上面写着
警告:set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /mounted-storage/home61c/sub001/sc38639-USWQ/www/第32行的test/scripts/download.php
‰PNG
bla bla bla(我无法复制和粘贴下面的东西)
这是怎么回事?