【转】PHP读取服务器端文件提供弹出下载窗口

来源:互联网 发布:淘宝卖家必须掌握ps 编辑:程序博客网 时间:2024/05/21 09:16

转载自:http://blogread.cn/it/article/4376?f=wb

有些文件需要经过身份验证以后才能下载,我们不容用户知道下载的地址,甚至文件不存放在web文件夹下,感觉是不是做起来比较难呢?用PHP几行就可以了。这是在PHP官方手册提供的例子。

<?php$file = 'monkey.gif';if (file_exists($file)) {    header('Content-Description: File Transfer');    header('Content-Type: application/octet-stream');    header('Content-Disposition: attachment; filename='.basename($file));    header('Content-Transfer-Encoding: binary');    header('Expires: 0');    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');    header('Pragma: public');    header('Content-Length: ' . filesize($file));    ob_clean();    flush();    readfile($file);}?>


0 0
原创粉丝点击