Report this

What is the reason for this report?

How to set permissions to allow scripts to add files

Posted on November 14, 2014

Hi,

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:

<?PHP

$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.

Thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi! The target path is missing a slash:

<?php

$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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.