0

I am trying to replace the uploaded file into a location.

My code is:

if (isset($_FILES['image']['name']))       
{
    $saveto = 'img/$user.jpg';      //$user would be the name of the current user.
    move_uploaded_file($_FILES['image']['tmp_name'], $saveto);
}

I'm getting this error,

Warning: move_uploaded_file(img/$user.jpg): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/profile.php on line 33

Although the permissions are set, sudo chmod 777. It is still giving me this error, what is the problem? Thanks

savanto
  • 4,470
  • 23
  • 40
Can't see me
  • 501
  • 1
  • 12
  • 23

1 Answers1

0

Two things.

First, you change $saveto = 'img/$user.jpg'; to $saveto = "img/$user.jpg";. In PHP declaring strings with ' and " have different behaviours. With ' it won't fetch the value of $user into the string, instead it will write $user literally.

But this is not the error. The error is that you don't have permission to create the file in the directory /img/. Make sure you have set the right permissions in this folder.

Or maybe it's because $ isn't a valid symbol for file name in Linux, I'm not sure about that though.

Havenard
  • 27,022
  • 5
  • 36
  • 62