<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限制对目录中文件的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <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>