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

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

        <tfoot id='bBGsy'></tfoot>
      1. 允许用户在 webroot 之外下载文件

        Allow users to download files outside webroot(允许用户在 webroot 之外下载文件)

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

          • <bdo id='62FAy'></bdo><ul id='62FAy'></ul>
                <legend id='62FAy'><style id='62FAy'><dir id='62FAy'><q id='62FAy'></q></dir></style></legend>
                <tfoot id='62FAy'></tfoot>

                  <tbody id='62FAy'></tbody>
              1. <small id='62FAy'></small><noframes id='62FAy'>

                  本文介绍了允许用户在 webroot 之外下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Hello I am using PHP to allow users to upload files and I have them sitting in a folder outside webroot (/var/www) folder for security reasons. It is in the folder /var/uploads. A user uploads files for specific records. Once the the uploaded files are moved to the uploads folder, the address of the attachment is stored in the database. Now whenever a user checks the record, attachments for the specific record are going to be displayed for downloads.

                  Since they are out of the webroot, I am unable to get them downloaded as they would have a url of

                  http://localhost/var/uploads/attachment.txt

                  Do we have a solution or should it downloadable folders be child directories of the webroot?

                  <?php
                  $con = mysql_connect("localhost","id","pass");
                  if (!$con)
                    {
                    die('Could not connect: ' . mysql_error());
                    }
                  
                  mysql_select_db("db", $con);
                  
                  $result = mysql_query("select * from attachments");
                  
                  while($row = mysql_fetch_array($result))
                  {
                  echo '<a href="'.$row[2].'" target="_blank">Download</a>--'.$row[3].'<br>';
                  }
                  
                  mysql_close($con);
                  ?> 
                  

                  is the code I am using. The folder's owner is www-data:/ or the web server. So there should be no access issues.

                  解决方案

                  Use

                  • a symlink pointing to /var/uploads (tutorial here)

                  • a Apache Alias directive Alias /uploads /var/uploads (must be in httpd.conf)

                  • or a proxy PHP script that accepts a GET variable filename=upload.jpg and fetches the file e.g. using fpassthru()

                  the latter is the least preferable option because it is resource intensive, but sometimes it's the only alternative. It also needs proper securing to prevent an attacker from getting other files on your server through the proxy.

                  这篇关于允许用户在 webroot 之外下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='06dD5'></tbody>
                1. <legend id='06dD5'><style id='06dD5'><dir id='06dD5'><q id='06dD5'></q></dir></style></legend>

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

                        <small id='06dD5'></small><noframes id='06dD5'>

                          <bdo id='06dD5'></bdo><ul id='06dD5'></ul>

                          <tfoot id='06dD5'></tfoot>