<legend id='GEUoW'><style id='GEUoW'><dir id='GEUoW'><q id='GEUoW'></q></dir></style></legend>
  • <i id='GEUoW'><tr id='GEUoW'><dt id='GEUoW'><q id='GEUoW'><span id='GEUoW'><b id='GEUoW'><form id='GEUoW'><ins id='GEUoW'></ins><ul id='GEUoW'></ul><sub id='GEUoW'></sub></form><legend id='GEUoW'></legend><bdo id='GEUoW'><pre id='GEUoW'><center id='GEUoW'></center></pre></bdo></b><th id='GEUoW'></th></span></q></dt></tr></i><div id='GEUoW'><tfoot id='GEUoW'></tfoot><dl id='GEUoW'><fieldset id='GEUoW'></fieldset></dl></div>

      <bdo id='GEUoW'></bdo><ul id='GEUoW'></ul>

      <tfoot id='GEUoW'></tfoot>

      <small id='GEUoW'></small><noframes id='GEUoW'>

        php限制对目录中文件的访问

        php restrict access to files in directory(php限制对目录中文件的访问)

        <legend id='WuxUz'><style id='WuxUz'><dir id='WuxUz'><q id='WuxUz'></q></dir></style></legend>
          <tbody id='WuxUz'></tbody>
            <bdo id='WuxUz'></bdo><ul id='WuxUz'></ul>

          • <i id='WuxUz'><tr id='WuxUz'><dt id='WuxUz'><q id='WuxUz'><span id='WuxUz'><b id='WuxUz'><form id='WuxUz'><ins id='WuxUz'></ins><ul id='WuxUz'></ul><sub id='WuxUz'></sub></form><legend id='WuxUz'></legend><bdo id='WuxUz'><pre id='WuxUz'><center id='WuxUz'></center></pre></bdo></b><th id='WuxUz'></th></span></q></dt></tr></i><div id='WuxUz'><tfoot id='WuxUz'></tfoot><dl id='WuxUz'><fieldset id='WuxUz'></fieldset></dl></div>
          • <tfoot id='WuxUz'></tfoot>

                • <small id='WuxUz'></small><noframes id='WuxUz'>

                  本文介绍了php限制对目录中文件的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图限制对目录中文件的直接访问.所以例如我有website.com/files/example.flv.

                  I am trying to restrict direct access to files in a directory. So for example i have website.com/files/example.flv.

                  因此,如果用户直接访问 URL 中的文件,我希望他们被重定向到主页.

                  So if users go straight to the file in the URL, i want them to be redirected to the home page.

                  我使用 htaccess 尝试了以下操作

                  I have tried the following using htaccess

                  deny from all
                  

                  但效果不佳.有没有一种方法可以使用 php 执行此操作,然后在用户直接转到 url 中的文件时,他们将被重定向.

                  but its not working great. Is there a way i could do this using php, then in the user goes straight to the file in the url, they will get redirected.

                  因此,如果用户转到 url 中的文件链接,他们将被发送到主页.所以这只能使用 htaccess 来完成

                  So if the user goes to the file link in the url, they will be sent to the home page. So can this only be done using htaccess

                  推荐答案

                  如果您想限制对文件的访问,您应该考虑将它们存储在公共 DocumentRoot 之外并使用 PHP 来交付文件,应用您自己的访问逻辑.这意味着在 www 或 public_html 文件夹之外,具体取决于您使用的托管环境.

                  If you want to restrict access to files, you should consider storing them outside the public DocumentRoot and using PHP to deliver the file, applying your own access logic. This means outside the www or public_html folders, depending on the hosting environment you are working with.

                  <?php
                  
                  // Suppose your "public_html" folder is .
                  $file = './../data/test.gif';
                  $userCanDownloadThisFile = false; // apply your logic here
                  
                  if (file_exists($file) && $userCanDownloadThisFile) {
                      header('Content-Description: File Transfer');
                      header('Content-Type: application/octet-stream');
                      header('Content-Disposition: attachment; filename=filename.gif');
                      header('Content-Transfer-Encoding: binary');
                      header('Expires: 0');
                      header('Cache-Control: must-revalidate');
                      header('Pragma: public');
                      header('Content-Length: ' . filesize($file));
                      ob_clean();
                      flush();
                      readfile($file);
                  }
                  

                  这篇关于php限制对目录中文件的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                    <tbody id='gLHDI'></tbody>

                        <small id='gLHDI'></small><noframes id='gLHDI'>

                      1. <i id='gLHDI'><tr id='gLHDI'><dt id='gLHDI'><q id='gLHDI'><span id='gLHDI'><b id='gLHDI'><form id='gLHDI'><ins id='gLHDI'></ins><ul id='gLHDI'></ul><sub id='gLHDI'></sub></form><legend id='gLHDI'></legend><bdo id='gLHDI'><pre id='gLHDI'><center id='gLHDI'></center></pre></bdo></b><th id='gLHDI'></th></span></q></dt></tr></i><div id='gLHDI'><tfoot id='gLHDI'></tfoot><dl id='gLHDI'><fieldset id='gLHDI'></fieldset></dl></div>

                        • <tfoot id='gLHDI'></tfoot>
                        • <legend id='gLHDI'><style id='gLHDI'><dir id='gLHDI'><q id='gLHDI'></q></dir></style></legend>

                          • <bdo id='gLHDI'></bdo><ul id='gLHDI'></ul>