php隐藏实际文件地址

*文
发布: 2023-03-18 15:18:01
原创
2623 人浏览过

php如何隐藏实际文件地址?这篇文章主要介绍了php隐藏实际地址的文件下载方法,涉及php中header与file_get_contents方法的相关使用技巧。希望对大家有所帮助。

本文实例讲述了php隐藏实际地址的文件下载方法。分享给大家供大家参考。具体如下:

下面这段php代码可不透露实际的文件下载地址。


function download_document($filename,$path="",$mimetype="application/octet-stream")
{
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Disposition: attachment; filename = $filename");
 header("Content-Length: " . filesize($pathto . $filename));
 header("Content-Type: $mimetype");
 echo file_get_contents($pathto . $filename);
}
登录后复制


实现方法二:


<?php
$file = "1.txt";// 文件的真实地址(支持url,不过不建议用url)
if (file_exists($file)) {
  header(&#39;Content-Description: File Transfer&#39;);
  header(&#39;Content-Type: application/octet-stream&#39;);
  header(&#39;Content-Disposition: attachment; filename=&#39;.basename($file));
  header(&#39;Content-Transfer-Encoding: binary&#39;);
  header(&#39;Expires: 0&#39;);
  header(&#39;Cache-Control: must-revalidate, post-check=0, pre-check=0&#39;);
  header(&#39;Pragma: public&#39;);
  header(&#39;Content-Length: &#39; . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
}
?>
登录后复制

相关推荐:

php 文件读取系列方法详解

php 文件分割与合并(断点续传)

PHP 下载 file_put_contents vs readfile

以上是php隐藏实际文件地址的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!