I’m taking a pictures with a webcam via flash and posting the data to the server to manipulate later.
Just switched from shared hosting to a Amazon’s EC2 instance(server).
I get this error:
Warning: file_put_contents(uploads/20120615104908.jpg): failed to open stream: Permission denied in /var/www/html/addons/webcam/capture.php on line 4 ERROR: Failed to write data to 20120615104908.jpg, check permissions
This is the code that’s failing.
When I change the chmod of uploads/ to 0777 it works but I’m afraid that’s unsafe to do.
(I apologize for the poorly writtenness I only recently got time because of this bug to revisit this code, I promise you I will form it better 😀 )
$filename = date('YmdHis') . '.jpg';
$imageData = file_get_contents('php://input');
$result = file_put_contents( 'uploads/' . $filename, $imageData );
if (!$result) {
print "ERROR: Failed to write data to $filename, check permissions\n";
exit();
}
$url = $filename;
$_SESSION['imageName'] = $filename;
print "$url\n";
Yes, it’s really unsafe.
You need to check the owner of
uploads/. It must be the same user that runs you PHP scripts (wwwdata or apache or something like this).That’s all!