Jump to content

folder secured, but can read from


NeilLindberg

Recommended Posts

Hi.

I've read many many articles online about .htaccess and I am somewhat a PHP programmer already...

 

I have a list of Uploads - MIME types stored in database... They are all uploaded by a logged-in user to an 'uploads' folder.

 

But, while my get_file.php?name=nameOfFile.ext totally works in the process...

Say the file is a picture: uploads/myPic.jpg

Well, the get_file.php?name=myPic.jpg works... but, so does http://mysite.com/upload/uploads/myPic.jpg !

I want this to not work. I can break it with a .htaccess file, but then my get_file.php doesn't work.

 

Is there a way (I KNOW THERE HAS TO BE!!) to protect a directory so only a call to get_file.php (which checks for active logged-in PHP/mySQL session) will allow retrieval of my uploads/ files???

 

Thank You!

Neil

Link to comment
https://forums.phpfreaks.com/topic/61946-folder-secured-but-can-read-from/
Share on other sites

Here is my get_file.php (uses mime from db to write header):

 

require_once("../../includes/testDBconfig.php");

if (file_exists($_GET['name'])) {

//echo $_GET['name'];

$query = "SELECT * FROM raw_uploads WHERE file_name='".$_GET['name']."'";

$result = mysql_query($query) or die("Something went wrong trying to get file info. $query");

if(mysql_num_rows($result) == 0){

echo "Select info from database returned empty.";

} else{

while(list($file_name, $user_id, $file_mime, $file_size) = mysql_fetch_row($result)){

//echo "Mime: $file_mime";

header("Content-type: $file_mime");

header("Content-length: $file_size");

header("Content-disposition: attachment; filename=$file_name");

readfile("$file_name");

}

}

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.