该脚本将处理文件的下载,它包括一个缓冲/不同类型的分机(如果你愿意的话)。隐藏链接的好方法是将文件放在受保护的目录中,并将链接存储在数据库中。用户看到与文件绑定的ID或会话,服务器找到并提供文件。
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "txt":
header("Content-type: application/txt"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default:
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
的.htaccess保护目录(你应该有一个目录只有这些文件
deny from all
上面的脚本修改为你的:
$file = "../".$realFileName;
$fakeFileName= 'Upbaz.ir-'.base64_decode($_GET['ffname']);
if ($fd = fopen ($file, "r")) {
$fsize = filesize($file);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$fakename\"");
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
我必须在服务器上安装patchinfo,因为我现在没有它 – 2013-02-21 17:00:52
[pathinfo](http://php.net/manual/en/function.pathinfo.php)是一个内置的PHP函数,你真的需要Ť他的文件有不同的名称,或仅仅是为了保护他们找到真正的文件? – UnholyRanger 2013-02-21 17:02:21
和它的类似我的代码没有不同...你确定我没有打破与此下载? – 2013-02-21 17:03:39