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

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

                  相关文档推荐

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