php隐藏文件下载路径实例

前端之家收集整理的这篇文章主要介绍了php隐藏文件下载路径实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如果我们需要隐藏下载文件路径我们只要直接输入就可以了,而不需要跳转路径,下面我们来看一个实例,希望对各位同学会有所帮助,代码如下:

  1. <?PHP  
  2.    
  3. //设置头信息,强制下载文件  
  4. function download_send_headers($filename) {  
  5.     // disable caching  
  6.     $now = gmdate("D, d M Y H:i:s");  
  7.     header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");  
  8.     header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");  
  9.     header("Last-Modified: {$now} GMT");  
  10.    
  11.     // force download  
  12.     header("Content-Type: application/force-download");  
  13.     header("Content-Type: application/octet-stream");  
  14.     header("Content-Type: application/download");  
  15.    
  16.     // disposition / encoding on response body  
  17.     header("Content-Disposition: attachment;filename={$filename}");  
  18.     header("Content-Transfer-Encoding: binary");  
  19. }  
  20. $file_name='download.csv';  
  21. $file_path=dirname ( __FILE__ ).'/file/'.$file_name;  
  22. download_send_headers($file_name);  
  23. readfile($file_path);  
  24. exit;  
  25. ?> 

猜你在找的PHP相关文章