# php... unable to upload files.

**URL:** <https://boards.straightdope.com/t/php-unable-to-upload-files/430217>\
**Category:** Factual Questions\
**Created:** [December 16, 2007, 6:37pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217 "2007-12-16T18:37:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [December 16, 2007, 6:37pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/1 "2007-12-16T18:37:31Z")

</div>

I am wondering if anyone can give me some advice on what to check/look at to solve the following problem.

I had an image uploader which once worked… then my site became unusable because a trial period expired.

Then I paid up and got my site back (but my host company are complete tools and haven’t done it properly… so I eventually got it sorted myself by altering the permissions on the .htaccess file)

but now that I’ve got the site ‘back’ I still have a few problems with certain parts.

I have an image uploader which now produces the following error…

"Uploading file 1191543704997.jpg…  
Warning: move\_uploaded\_file(1191543704997.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/\<r\>/public\_html/photos/upload\_multiple.php on line 60

Warning: move\_uploaded\_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phprtJ89G’ to ‘1191543704997.jpg’ in /home/\<r\>/public\_html/photos/upload\_multiple.php on line 60  
There was an error uploading the file!"

I have played about with the permissions on the tmp folder, to no avail.

eta: ‘\<r\>’ is meaninglesss… I just replaced my site username with that for security purposes.

---

<div class="post-metadata">

**Author:** ![ticker](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@ticker](https://boards.straightdope.com/u/ticker)\
**Post date:** [December 16, 2007, 7:37pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/2 "2007-12-16T19:37:13Z")

</div>

I don’t know php ☹ but could it be a server problem, not a php or OS file permissions issue? Some servers restrict where files may be placed as a security measure.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [December 16, 2007, 7:45pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/3 "2007-12-16T19:45:11Z")

</div>

[QUOTE=ticker]  
I don’t know php ☹ but could it be a server problem, not a php or OS file permissions issue? Some servers restrict where files may be placed as a security measure.  
[/QUOTE]

If it is then it’s a _new_ thing on my server. The code worked before my trial period ran out.

if it helps anyone here’s the code on line 60…

"if(move\_uploaded\_file($\_FILES[‘file’.i]['tmp\_name'], basename( \_FILES[‘file’.$i][‘name’]))) "

---

<div class="post-metadata">

**Author:** ![Caught\_Work](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Caught\_Work](https://boards.straightdope.com/u/Caught_Work)\
**Post date:** [December 16, 2007, 10:18pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/4 "2007-12-16T22:18:44Z")

</div>

Permissions on the folder that the file is being moved into need to be set to 777.  
Probably the photos diretory.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [December 16, 2007, 10:21pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/5 "2007-12-16T22:21:58Z")

</div>

[QUOTE=Caught@Work]  
Permissions on the folder that the file is being moved into need to be set to 777.  
Probably the photos diretory.  
[/QUOTE]

DUDE! That worked. Thanks 🙂

I’ts a simple answer too. I can’t believe I didn’t try it. I was assuming there was something wrong with the source folder. It never occured to me there might be something wrong with the permissions onthe destination folder.

---

<div class="post-metadata">

**Author:** ![larsenmtl](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@larsenmtl](https://boards.straightdope.com/u/larsenmtl)\
**Post date:** [December 16, 2007, 10:24pm UTC](https://boards.straightdope.com/t/php-unable-to-upload-files/430217/6 "2007-12-16T22:24:08Z")

</div>

From the error msg and small snippet of code, it looks like the upload script uploads to /tmp/phprtJ89G and then moves the file ‘elsewhere’. It looks like you don’t have permission to the ‘elsewhere’. If basename($\_FILES[‘file’.$i][‘name’]) resolves to just ‘1191543704997.jpg’ then it’s attempting to move it to where the script is executing from, /home/\<r\>/public\_html/photos/. You’ll need to give the user running the webserver (if it’s a generic apache install, for example, the user is ‘apache’) permission to write to that folder.

Edit: looks like I was beat to the punch. Be warned though, 777 is essentially giving anybody and everybody full permission to that folder. You might want to tailor it back a bit.
