Jump to content

Recommended Posts

Hi

 

I've got a file upload script i've written and I have set the folder to 777 to allow uploads

 

With the permission set to 777 does this open me up to potential uploads from 3rd parties? (ie: viruses etc)?

 

So I thought what I would do is

 

1: Set folder to 777 to allow uploads

2: Upload file

3: Set folder to 755 to disable uploads

 

Would this be the best method to do it?

 

Or is that a waste of time and am I safe just leaving it as 777

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/
Share on other sites

1a. Viruses can't do anything unless they're executed. So to prevent viruses from doing anything, don't execute files.

1b. If you're actually worried about viruses being uploaded, install AV software on the server and manually scan files as they're uploaded.

2. Store uploads in a place that is not web accessible. Or prevent the webserver from allowing access to them.

3*. Have PHP create the upload folder: chmod 0777 the parent folder, use mkdir() to create the upload folder then chmod() 0755 it, then chmod 0755 the parent folder.

4. Use a PHP script to send (eg, show or trigger a download on) an uploaded file. Don't link to the files directly - though you could have URL rewriting make it look like you are. Don't forget access controls.

 

* If the server configuration is altered and the PHP user changes, you'll have to do a little work. But this is pretty rare.

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1345073
Share on other sites

  • 2 weeks later...

thanks, so how can I set that?

 

You chmod the parent through your ftp client or an ssh session.  Once the parent is 777 drop in a quick script to make and chmod the upload directory:

 

<?php
mkdir('uploads');
chmod('uploads', 0755);

 

Browse to the URL for that script so it creates the directory and then remove that script.

 

After the directory is created then use your ftp/ssh to set the parent back to 755

 

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347523
Share on other sites

so if I already have a folder called "uploads", then surely I wouldn't run

 

mkdir('uploads');

 

because the folder exists.

 

but when I try and CHMOD that folder with

 

chmod('uploads', 0755);

 

then I get

 

Warning: chmod() [function.chmod]: Operation not permitted in /home/web101/public_html/myadmin/upload.php on line 4

 

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347560
Share on other sites

You would have to remove your existing uploads folder and re-create it using PHP in order to do as suggested.  Take the current folder and rename it to something else, for instance uploads.old.  Then use the php script to create the new folder with the proper permissions, as well as copy over all the old files.  Remove the old uploads folder when done.

 

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347568
Share on other sites

the only problem is that the folder contains many files and it's the main folder for all the uploads, so it would mean I would have to copy hundreds of files each time someone uploads a new file

 

basically all I need to do, is make a secure way of uploading a file to a folder, but from what I can see it looks like the only option is to create a new folder in the root each time

 

my goal is just to have a script which files can be uploaded to a defined folder location, but the folder is secured with permissions to stop outsiders uploading anything such as scripts \ viruses etc

 

any suggestions would be great

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347578
Share on other sites

the only problem is that the folder contains many files and it's the main folder for all the uploads, so it would mean I would have to copy hundreds of files each time someone uploads a new file

 

You are missing the point here. Let's break it down:

 

1. Rename existing "uploads" folder to "uploads.old".

2. Use PHP to create a new "uploads" folder; mkdir('uploads');

3. Use PHP to CHMOD the newly created "uploads" folder; chmod('uploads', 0755);

4. Copy the contents from "uploads.old" to "uploads".

5. Delete "uploads.old".

 

Whenever someone uploads something in the future, it will go to the newly-created "uploads" folder - you don't have to do anything.

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347583
Share on other sites

ok thanks, i'll give that a go

 

is that solution practical when you might have 000's of files in the uploads folder, surely it's going to have some serious pressure on the server if uploads are constantly being done and it's being required to shift 000's of files

 

also, what would you suggest if you have multiple users uploading files, surely if folders are being renamed, files being moved etc, then files are going to go missing. Or would it be the case of having 1 folder per user in the root?

Link to comment
https://forums.phpfreaks.com/topic/262467-folder-permissions/#findComment-1347593
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.