How to set permissions to allow scripts to add files

November 14, 2014 828 views


I'm new to servers in general, and am having some trouble understanding permissions. I know that when I create a file using Notepad++ FTP client I have to set permissions using chmod in the terminal window in order to be able to write to it using scripts.

Right now I am trying to take a picture using a serial camera and upload it using a multi-part form data request on a php script titled camera.php. Here is the script for reference:


$target_path = "var/www/html/Picture";

$target_path = $target_path . basename( $_FILES['picture']['name']);
$file = "/var/www/html/camera.html";

if(move_uploaded_file($_FILES['picture']['tmp_name'], $target_path)) {
 echo "The file ". basename( $_FILES['picture']['name']).
 " has been uploaded";
 file_put_contents($file, "Success", FILE_APPEND);

else {
 echo "There was an error uploading the file, please try again!";
 file_put_contents($file, "Fail", FILE_APPEND);


On the camera/hardware side it says that it is transmitting, but the picture does not show up on the server. Is this due to a permission issue? Any guidance is much appreciated.


1 Answer

Hi! The target path is missing a slash:


$target_path = "/var/www/html/Picture";

Without it, PHP considers it a relative path so it tries to save the image to /var/www/html/var/www/html/Picture (assuming that your PHP file is in /var/www/html) which isn't what you want.

Have another answer? Share your knowledge.