I'm working on a page where a user can upload an image/video using a form. The code includes this line:
move_uploaded_file($tempfile, $newfile)
Then a thumbnail is automatically created from this image/video and uploaded to the server like this:
file_put_contents($thumbname, $thumbnail)
Now the uploading of the image works perfectly but the thumbnail can't be saved and I get this response:
Warning: file_put_contents(thumbnails/1.jpg): failed to open stream: Permission denied in SITEURL/upload.php on line 17
My two questions:
Why does the user have permission uploading an image via
move_uplaoded_file
but uploading the thumbnail viafile_put_contents
gets denied? Please note that both files, image AND thumbnail, get uploaded to the same folder. Shouldn't the user have either permission to do both or neither?I do realize there is already a thread like this but the suggested answer there is to run
chmod 777
. But I read that setting a folder to 777 is always a security risk. Is there a way to fix this problem without 777?
Again, I don't understand why I have to change the permission to 777 forfile_put_contents
whereasmove_uploaded_file
works just fine at 755.