Solved

move_uploaded_file and ownership/permissions

Posted on 2006-07-19
2
978 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 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