Home > php教程 > php手册 > php运用readfile函数给隐藏下载文件地址增加权限判断

php运用readfile函数给隐藏下载文件地址增加权限判断

WBOY
Release: 2016-06-21 08:52:01
Original
895 people have browsed it

1 以上代码实现了真是URL路径的隐藏功能, 本页开头可以进行权限判断。

2 效果如图,我们看到下面文件下载的URL已经被test.php隐藏.

 

 


02 $file = get_file_address();// 文件的真实地址(支持url,不过不建议用url)
03
04 if (file_exists($file)) {
05 header('Content-Description: File Transfer');
06 header('Content-Type: application/octet-stream');
07 header('Content-Disposition: attachment; filename='.basename($file));
08 header('Content-Transfer-Encoding: binary');
09 header('Expires: 0');
10 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
11 header('Pragma: public');
12 header('Content-Length: ' . filesize($file));
13 ob_clean();
14 flush();
15 readfile($file);
16 exit;
17 }
18 ?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template