//检查文件是否存在
if (!is_file($file)) { die("文件不存在"); }
//取得文件大小
$len = filesize($file);
//取得不包含路径信息的文件名
$filename = basename($file);
//输出http头信息
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
Header("Content-type: application/application/octet-stream");
header("Content-Disposition: attachment; filename=". $filename);
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $len);
//输出文件
@readfile($file);这个方法可以很好的实现隐藏文件具体位置。
但是有个问题我一直无法解决,就是如何实现断点续传功能。
在实际使用中如果使用flashget之类的断点续传软件会下载不到文件。
更具体的例子可以参见:
http://cn.php.net/manual/zh/function.header.php
中的note部分。
670

被折叠的 条评论
为什么被折叠?



