Jump to content

Need help implementing safe method


yaMz

Recommended Posts

I am trying to implement what I call private uploads. Basically, users can check a box to indicate they want their file "private"

 

If so, the upload location is then (exampled as): _domain_/private-folder/$randomfolder

 

Upon uploading their file, the random folder is created, their file moved to the directory, the upload information stored to the database, .htaccess file is created like so:

 

 

info to add to new .htaccess:

<files "*.*">
Deny from All
</files>

<files "*.*">
Allow from 
$domains
</files>

 

the string $domains is the domains they enter each seperated by a new line in a form textarea.

 

The problem - how can I make sure this is safe. i.e. I want the string to be obviously proofed with php so that no matter what they input, only domains will be outputted.

 

I don't need code written for me (maybe), I'm just unsure of the necessary methods I should use.

 

Link to comment
Share on other sites

The existence doesn't bother me. Anyways I'm a bit rusty - If you will, what specific set of expressions should I run on the string to ensure they wont add .htaccess lines of their own? A non-by-passable expression set is what I'm finding difficult to create.

Link to comment
Share on other sites

I would do this by having a single folder to store all of the private uploads, with a htaccess in it that says deny access to all files for everyone.

 

When the private files are uploaded through a form, store the files in the private folder and store a recrod in a mysql table with the filename.

 

Next I would have a PHP script that determines whether or not a user is allowed to download one of the private files. If they are allowed then use readfile() to output the file to the user. I would also need to send the correct header() for whatever type of file it is.

 

That way you can write PHP code to determine if the user is allowed to access the file requested, and the location of the private files will never be shown to any users, even if someone knew the location, they won't get direct access because of the htaccess rule.

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.