Solved

move_uploaded_file and ownership/permissions

Posted on 2006-07-19
2
974 Views
Last Modified: 2011-10-03
Hello.

The following comment was posted by jest3r: (http://ca.php.net/manual/en/function.move-uploaded-file.php#57959)

                  "It seems that move_uploaded_file use the GROUP permissions of the parent directory of the tmp
                  file location, whereas a simple "copy" uses the group of the apache process. This could create a
                  security nighmare if your tmp file location is owned by root:wheel"

I have run into this problem.  How can I get around it?  Is there another command, or a custom function that would do the trick?

 
0
Comment
Question by:hankknight
2 Comments
 
LVL 14

Assisted Solution

by:ThG
ThG earned 100 total points
ID: 17137827

no, that's not possible unless your system has screwed up permissions (like setgid /tmp directory?).

how can you assert that you have run into this problem?

you can get more information about what's going on this way:

var_dump(stat($_FILES['....']['tmp_name']));
0
 
LVL 9

Accepted Solution

by:
cristi_2112 earned 400 total points
ID: 17138250
The best solution is to make a habit of running a chmod command after each upload with the desired rights.
So after each:
move_uploaded_file($file['tmp_name'], $destination.'/'.$file['name']);

call:
chmod($destination . '/' . $file['name'], $permissions);
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP populating an array. 4 25
preventing spam with mailto 22 31
Showing random records from database 10 37
PHP Query return divisible by 3 3 17
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question