Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: move_uploaded_file(): Unable to move '/

I keep getting this error on a new server I just setup

[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning:  
move_uploaded_file(upload/110216104651_00134_smooth_1440x900.jpg): 
failed to open stream: Permission denied in /var/www/admin/_application/models/Roles.model on line 1757, 
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning:  move_uploaded_file():
Unable to move '/tmp/php6wlOg1' to    'upload/110216104651_00134_smooth_1440x900.jpg' 
in /var/www/admin/_application/models/Roles.model on line 1757, referer:
http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Notice:  
Upload Error: Error moving from temp dir in /var/www/admin/_application/models/Roles.model on line 1759,
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4

I added 777 and created a uploads dir, but the error persists. How do I find the path that needs to either be corrected or created?

like image 213
Matt Elhotiby Avatar asked Feb 16 '11 22:02

Matt Elhotiby


People also ask

What is move_uploaded_file in PHP?

move_uploaded_file (PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8) move_uploaded_file— Moves an uploaded file to a new location

Why is move_uploaded_file () not working?

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE.

How to check if PHP has access to an upload file?

For example, if upload directory is actually located in /var/upload, then make sure that is in your statement, not just upload /. Show activity on this post. Make sure the file is within your public html root, otherwise double check the owner of the file, and make sure PHP Has read / write access to it.

Why can't I upload large files in PHP?

down -4 Anonymous¶ 14 years ago If you find that large files do not upload in PHP even though you've changed the max_upload_size , this is because you need to change the max memory size varible too. The entire file is loaded into memory before it is saved to disk. up down -4 Ray.Paseur sometimes uses Gmail¶ 11 years ago


3 Answers

Change owner of upload/ to www-data:www-data and also chmod to 755

like image 197
teecee Avatar answered Oct 16 '22 04:10

teecee


Looks like it doesn't know where upload/ is. Make sure you have the full path in your statement. For example, if upload directory is actually located in /var/upload, then make sure that is in your statement, not just upload/.

like image 38
pioniere Avatar answered Oct 16 '22 04:10

pioniere


Log into your ftp and confirm the following:

  • The folder exists, check for spellings
  • Check the properties of the folder and make sure the permissions have read+write 0666
  • Make sure the file is within your public html root, otherwise double check the owner of the file, and make sure PHP Has read / write access to it.

looking at the log:

Unable to move '/tmp/php6wlOg1' to    'upload/110216104651_00134_smooth_1440x900.jpg' 

It seems to me that its looking in your root directory as upload/110216.... should be path.to/public_html/upload/110216....

If none of the above work, please post your line of code that has move_uploaded_file on.

like image 29
RobertPitt Avatar answered Oct 16 '22 04:10

RobertPitt