php - Allow users to download files outside webroot -
hello using php allow users upload files , have them sitting in folder outside webroot (/var/www) folder security reasons. in folder /var/uploads. user uploads files specific records. once the uploaded files moved uploads folder, address of attachment stored in database. whenever user checks record, attachments specific record going displayed downloads.
since out of webroot, unable them downloaded have url of
do have solution or should downloadable folders child directories of 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 * attachments"); while($row = mysql_fetch_array($result)) { echo '<a href="'.$row[2].'" target="_blank">download</a>--'.$row[3].'<br>'; } mysql_close($con); ?>
is code using. folder's owner www-data:/ or web server. there should no access issues.
use
a apache
alias
directivealias /uploads /var/uploads
(must in httpd.conf)or proxy php script accepts variable
filename=upload.jpg
, fetches file e.g. usingfpassthru()
the latter least preferable option because resource intensive, it's alternative. needs proper securing prevent attacker getting other files on server through proxy.
Comments
Post a Comment