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
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");

}

}

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.