Sti
Sti

Reputation: 8484

Setting permissions in PHP on server

I am trying to create a really simple webpage in php, letting people upload images to a folder on my server. I made this really simple with some done code, and it worked awesomely on my computer with xampp, but when I upload the page to my server, it gets an error message every time I upload anything. The error is when the script checks if the image was uploaded, where it says

$copied = copy($_FILES['image']['tmp_name'], $newname);
if(!$copied)
   echo "error";

This leads me to believe that there is something wrong with the permissions. But how can I set this? And what should I set it to? I just need others to be able to upload images to a spesific folder.

Upvotes: 1

Views: 3803

Answers (1)

nickb
nickb

Reputation: 59699

The web server needs write permissions to be able to write into the directory you're storing the images.

Assuming you're on a Linux server, run the following command on the server (ssh) after changing /path/to/uploaded/images to the image upload directory, and see if it solves the problem:

chmod 777 /path/to/uploaded/images

If that fixes the problem, you can probably relax the permissions to something like:

chmod 664 /path/to/uploaded/images

These are basic commands for directory permissions, which you can learn more about in this tutorial about file permissions on Linux.

Alternatively, you can use move_uploaded_file() to copy the uploaded file to a known location.

Upvotes: 1

Related Questions