Thu 10 Aug 2006
php实现受控的文件下载
Posted by Semon under PHP
No Comments
通过发送http实现,假设$filesize代表文件大小,$filename代表文件名,文件内容为filecontent
header(“Content-type: application/octet-stream”); //文件类型的mimetype
header(“Accept-Ranges: bytes”); //如果不需要显示文件尺寸可省略
header(“Accept-Length: “.$filesize); //同上
header(“Content-Disposition: attachment; filename=” . $filename);
echo $filecontent;
这样就可以隐藏文件的实际路径,比如保存在数据库中的文件等。

No Responses to “ php实现受控的文件下载 ”