保护下载
我只是在下面测试这个下载脚本。下载工作正常,但下载的 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>
I was just testing this download script below. The downloading works fine but the downloaded zip or rar archive is always corrupt and cannot be opened. I tested it on local development server as well as my hosting account.
I am just trying to learn how this works but I don't really understand it.
All help is appreciated!
Test Code:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很可能您在文件中附加/前置了一些内容。尝试使用缓冲和清理。
It mostly probable that you have something appended/prepended to the file. Try to use buffering and cleaning.
您是否已配置网络服务器(尤其是 Apache)来加载 mod_xsendfile?如果没有安装该模块,您的脚本基本上什么也不做。
Have you configured your webserver (Apache in particular) to load mod_xsendfile? Without that module installed, your script essentially does nothing.