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 之外下载文件

        时间:2023-08-20

        • <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 之外下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用PHP下载大文件(内存占用低) 下一篇:使用 PHP 打开下载对话框

                  相关文章

                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>