• 技术文章 >后端开发 >PHP问题

    php怎么隐藏路径下载

    藏色散人藏色散人2021-03-30 09:36:48原创488

    php隐藏路径下载的实现方法:1、通过“download_document”方法隐藏实际文件下载地址;2、通过“if (file_exists($file)) {...}”方式隐藏实际文件下载地址。

    本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

    php隐藏实际文件下载地址的方法

    文章主要介绍了php隐藏实际文件下载地址的方法,涉及php中header与file_get_contents方法的相关使用技巧,非常具有实用价值,需要的朋友可以参考下:

    实现方法一:

    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('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);
      exit;
    }
    ?>

    【推荐学习:PHP视频教程

    以上就是php怎么隐藏路径下载的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:php
    上一篇:php怎么去除非数字 下一篇:php.可以重启不
    PHP编程就业班

    相关文章推荐

    • debian怎么删除php• url index.php 怎么去掉• 一起看看php7带来的性能升级• php怎么获取图片文件的修改时间

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网