每当我使用这个脚本下载文件时,我都无法看到下载时的总大小和速度......我想让它看起来更像是"直接下载链接".此脚本的目的是隐藏直接下载链接限制直接下载和其他下载行为,如机器人.想想mediafire,rapidshare,megaupload等.
我们现在使用的脚本但是没有显示从正常下载链接下载时的显示方式,我将发布正在发生的事情的屏幕截图:

我希望这个截图有所帮助,因为我已经在互联网上搜索了几个小时,似乎无法找到解决方案:(.
if (isset($_GET['file'])){
$file = $_GET['file'];
$path = '/home/user/domains/domain.com/files/upload/';
$filepath = $path.$file;
if (file_exists($filepath)){
set_time_limit(0); // for slow connections
header('Content-Description: File Transfer');
header("Content-Disposition: attachment; filename=\"$file\"");
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($filepath));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
readfile($filepath); // send file to client
}
else{
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
}
}else{
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
}
Run Code Online (Sandbox Code Playgroud)
小智 2
内容是否在服务器级别使用 mod_deflate 或类似的东西进行压缩?
此处已回答此问题: Sending Correct file size with PHP download script
“如果您使用 Zlib、mod_deflate 等压缩文件,Content-Length 标头将不准确,因此您在下载文件时最终会看到“未知大小”和“未知剩余时间”。
“您可以在适用的 .htaccess 文件中使用以下行轻松地为单个脚本禁用它:
SetEnvIfNoCase Request_URI ^/download.php no-gzip dont-vary 这里假设download.php 位于服务器根目录路径(例如www.crimsonbase.com/download.php)的下载脚本中。(这是因为正则表达式是 ^/download.php。)”
另外,请注意您的脚本不安全。有人可以有效地发送 _GET['file'] 的以下获取参数
../../../../../Documents/MyStuff
Run Code Online (Sandbox Code Playgroud)
它会完全覆盖你的 $path 限制。
建议删除路径中的任何 .. 引用。
| 归档时间: |
|
| 查看次数: |
3308 次 |
| 最近记录: |