我想授予我的一些网站用户下载特定文件的权限。 下载需要恢复支持,只是为了方便用户。使用php下载安全和恢复支持文件
出于这个原因,它来到我的脑海的文件保护与这段代码:
// Check for user session and privileges if it's okay continue
ob_end_clean();
$data = file_get_contents("c:\\newdata.pdf");
$showname = "newdata.pdf";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=\"".$showname."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($data));
echo $data;
的问题是,不仅它不会恢复的支持也它gonno给我的web服务器一笔大开销,也需要的file_get_contents大文件也超过134217728个字节的文件大很多的内存,您将收到此错误信息:
的134217728个字节允许的内存容量用尽(试图分配188862464个 字节)
有什么建议吗?
只有'应用程序/八位字节stream'是官方应该由客户端下载的二进制数据的媒体类型。 – Gumbo 2009-09-22 13:04:03
可能的[在PHP中是否有好的部分文件下载实现?]的副本(http://stackoverflow.com/questions/1395656/is-there-a-good-implementation-of-partial-file-downloading-in -php) – 2013-04-04 11:31:16