更新
刚刚从我的错误日志中发现有readfile() has been disabled for security reasons
任何替代方法readfile()
吗?将fopen
或fread
使用 zip 文件?
==================================================== =================================
我的脚本:
<?php
$str = "some blah blah blah blah";
file_put_contents('abc.txt', $str); // file is being created
create_zip(array('abc.txt'), 'abc.zip'); // zip file is also being created
// now creating headers for downloading that zip
header("Content-Disposition: attachment; filename=abc.zip");
header("Content-type: application/octet-stream; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header('Content-Transfer-Encoding: binary'); // added this line as per suggestion
header('Content-Length: ' . filesize("abc.zip")); // added this line as per suggestion
readfile("abc.zip");
//echo 'do something'; // just for testing purpose to see if code is running till the end
exit;
当我运行上面的脚本时,我得到一个空白页(没有下载提示)。当我取消注释“做某事”行时,我会在屏幕上看到它。所以脚本一直运行到最后一行。
我也把它放在error_reporting(E_ALL)
页面的顶部,但什么都没有出现。
我在这里想念什么?