我只是测试下面的这个下载脚本。下载工作正常,但下载的zip或rar档案总是损坏,无法打开。我在本地开发服务器以及我的主机帐户上进行了测试。保护下载
我只是想学习这是如何工作,但我并不真正了解它。
所有帮助表示赞赏!
测试代码:
<?php
$is_logged_in = 1;
$path_to_file = 'downloads/tes.zip';
$file_name = 'test.zip';
if ($is_logged_in == 1)
{
header("X-Sendfile: $path_to_file");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$file_name\"");
exit;
}
?>
<h1>Permission denied</h1>
<p>Please Login first!</p>
在文本编辑器中打开文件。你看到了什么? – 2011-03-24 00:40:42
你不发送任何数据,是吗? – Gumbo 2011-03-24 00:41:13
您是否按照该代码的建议安装了'mod_xsendfile'? – icktoofay 2011-03-24 00:42:12