EchoFool Posted November 26, 2011 Share Posted November 26, 2011 Hi I have an image uploading script that won't upload images... It worked at one point when i had folder permission at 0777 but i was told that is risky so i changed it to 0775 Now it won't work and i can't use 0777. Any one know what i need to do to get it to work? This is my script: <?php $salt = 35322232414; $name = $salt.$safe; $name = md5($name); if(isset($_POST['submit'])){ if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 1000000)) { if ($_FILES["file"]["error"] > 0) { echo $_FILES["file"]["error"]; } else { $filename = md5(serverdate()) . $_FILES["file"]["name"]; if (file_exists("userimages/".$name."/".$filename)) { echo "Image already uploaded!"; } else { if (is_dir("userimages/".$name) == FALSE){ mkdir("userimages/".$name, 0775); //permissions } move_uploaded_file($_FILES["file"]["tmp_name"], "userimages/".$name."/" . $filename); echo "Image has been uploaded!"; } Error i get: Warning: move_uploaded_file(images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in uploadfile.php on line 41 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjrX3SO' to 'images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg' in uploadfile.php on line 4 Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/ Share on other sites More sharing options...
Laash Posted November 26, 2011 Share Posted November 26, 2011 Apply this php code on your uploads folder: <?php chown ("$your_uploads_folder", "$server_user"); ?> server_user is usually apache, data-www, httpd or some other server user that is allowed to upload files via php. Ask your hosting company, they must know who that user is. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291384 Share on other sites More sharing options...
EchoFool Posted November 26, 2011 Author Share Posted November 26, 2011 When you say apply it to the folder do you mean make the script in the folder and execute it or something else ? Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291386 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 If you're having a permission error it means you do not have write access granted on the specific directory. You can 1 - chown - change ownership of the directory (might work alone) 2 - chmod - change permissions - if you own the dir you can probably set it as 0755 otherwise you may need to use 0775, I wouldn't recommend using 0777 for security issues. Do you ssh into your server?? If so run an "ls -al" and you can see the current ownership and permissions. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291454 Share on other sites More sharing options...
EchoFool Posted November 27, 2011 Author Share Posted November 27, 2011 Okay your talking beyond my level here i just made the script above it worked on 0777 - beyond that ive never really touched permissions ... all my other folders/files are 0755. Which is fine. So were talking about alien stuff to me here If i change mod to 0755 it won't work when i did it manually. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291456 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 make sure the folder the script is saving the file to is chmod 0775 as well. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291457 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 ^^ the reason i suggest 0775 is you may only be in the group for that folder. which is why you need that second 7. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291458 Share on other sites More sharing options...
EchoFool Posted November 27, 2011 Author Share Posted November 27, 2011 The folder the files go to is 0775 and the script.php is 0775 aswell but i get permission denied. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291460 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 are you on a *nix box?? Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291463 Share on other sites More sharing options...
EchoFool Posted November 27, 2011 Author Share Posted November 27, 2011 Umm? Never heard of it.. My server is a Linux VPS if thats what you meant? Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291464 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 if it's working with permissions set to 0777 and not 0775 that would lead me to believe you are not the owner and not in the proper group. You may want to ping your system administrator just to be sure. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291465 Share on other sites More sharing options...
EchoFool Posted November 27, 2011 Author Share Posted November 27, 2011 The file and the folder the image uploads to all have the same name for the owner field. upload.php is tghh[502] folder "userimages" is tghh[502] The other owner option is root[0] which has not been used but i don't think it would make a difference? Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291468 Share on other sites More sharing options...
The Letter E Posted November 27, 2011 Share Posted November 27, 2011 you probably need to review your /etc/passwd file and find out which user php's process are being run by to be sure. You can also check /etc/group to see if you are in the necessary group/groups. If this is getting too in depth, you should probably contact your sys admin. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291475 Share on other sites More sharing options...
EchoFool Posted November 27, 2011 Author Share Posted November 27, 2011 I initially contacted my admin and they didn't solve it either. They changed the groups to what it currently is how ever. Link to comment https://forums.phpfreaks.com/topic/251821-script-wont-upload-the-image-permission-denied/#findComment-1291480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.