Move_uploaded_file(): Unable to move '/tmp/phpPKTrhf' to 'xarth.jpg'

Hello,
Ive been working through code show in the book ‘Learning PHP, MySQL, & JavaScript’ by Robin Nixon, in which he creates a social media site.

When trying to upload a file, I receive the following errors:
**Warning** : move_uploaded_file(xarth.jpg): failed to open stream: Permission denied in **/opt/lampp/htdocs/social_media/profile.php** on line **34**

**Warning** : move_uploaded_file(): Unable to move '/tmp/phpPKTrhf' to 'xarth.jpg' in **/opt/lampp/htdocs/social_media/profile.php** on line **34**

After reading posts about file/folder permissions, I changed the php.ini file to:
upload_tmp_dir="/opt/lampp/htdocs/social_media/upload/"

However, even after restarting Apache and MySQL servers, the error persists. phpinfo shows the updated file path.
Also, echo sys_get_temp_dir(); returns /tmp, so I am a bit confused as it seems that three folders are involved.

[EDIT] PHP is running as user daemon, which is the owner with read & write access to lampp/temp. I still cannot find the /tmp folder, even after searching the lampp directory. Well, there were tmp folders but for docs and phpmyadmin.

Any help would be appreciated,
Thank you.

You aren’t specifying the where.

move_uploaded_file($_FILES[‘uploaded’][‘tmp_name’], ‘upload/’)

Thank you for that.

I still had the error. I discovered that when I created the upload folder, the group permissions were set as the owner. I changed the group permissions to xamppusers, and now that error has gone.

All is working. :):smile:

That was the next step to look at. Glad you figured it out

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service