0
votes

I'm developing an image uploader script using php 5.3 Website is under shared linux hosting, everything seems to works fine, except that I can't move uploaded images to destination folders.

Warning: move_uploaded_file(images/2014091546_screen.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/user/public_html/upload.php on line 68

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpJwnzVo' to 'images/2014091546_screen.jpg' in /home/user/public_html/upload.php on line 68

I've tried to chown folder to 'nobody' user but it fires another error

The only thing thats helps is chmod folder to 0777, but it's a serious security hole, so that's not a solution. I've tried to chmod dynamically destination folder using the script to set first 0777 and revert to 0755 once the image is on place, but seems that PHP have no rights to do that.

Due to hosting limitation, I have no terminal or shell access, so there is no command line options to use.

Is there a solution in PHP to achieve that?

Thanks in advance.

1
Have you try to create folder using your PHP script and then set 0755? Check the folder owner then - MagyaDEV
Good point! I will give it a check and feedback. Thank you - Farid Silva Aboid
Mkdir is not allowed here Warning: mkdir() [function.mkdir]: Permission denied in /home/user/public_html/backend/upload.php on line 67 PHP user is "nobody" - Farid Silva Aboid

1 Answers

0
votes
hey it will definitely help u . try this code to move the image to your folder. 
code:
if(move_uploaded_file($_FILES['image']['tmp_name'],'images'.$_FILES['image']['name'])) //path of folder from where you wanted to upload
{
    $tmp=' upload_images'.$_FILES['image']['name'];
    $new = 'upload_images/uploads'.$_FILES['image']['name']; 
    echo "Image successfully";
}