marshmellows_17 Posted July 17, 2009 Share Posted July 17, 2009 Hello I am developing a website which requires images to be uploaded through a CMS my the company owner only. I have a upload.php(file browse option) which links to upload_file.php which works fine except when the files upload they are stored with a permission of 0600 and cannot for the life of me figure out how to change this automatically when the files upload. If I transfer the files through the FTP manually then the permission is correct (0644) but not when uploaded through my CMS. I have the following code for the upload_file: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/JPG") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("../images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "../images/" . $_FILES["file"]["name"]); echo "Stored in: " . "../images/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> I have tried variations of the following: chmod("../images/" . $_FILES["file"]["name"], 0644); Nothing seems to work, I either break the whole server folder with the images in it or I receive an error message. I can get the chmod to work if i manually enter the file name like: <?php chmod ("images/photo1.jpg", 0644); ?> but thats not much use when the company owner is uploading files as it would require the code to be added every time I have also tried changing the permissions when the files are being retrieved but that doesnt work either: (storing the filename in the database manually.) then retriveing it. photos.php $result = @mysql_query('SELECT * FROM tbl_images'); if (!$result) { exit('<p>Error Performing Query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { chmod("images/' . $row['filename'] . '",0644); I really am starting to get desperate as the client would like his website working properly but I am rather new to all this and this is just one thing I cannot seem to get my head around. Any help would be greatly appreciated Thank you Link to comment https://forums.phpfreaks.com/topic/166300-chmod-major-help-needed-permission-from-0600-to-064/ Share on other sites More sharing options...
zq29 Posted July 18, 2009 Share Posted July 18, 2009 Nothing seems to work, I either break the whole server folder with the images in it or I receive an error message. What is the error message? Link to comment https://forums.phpfreaks.com/topic/166300-chmod-major-help-needed-permission-from-0600-to-064/#findComment-877690 Share on other sites More sharing options...
calmchess Posted July 18, 2009 Share Posted July 18, 2009 I'd setup a user with chmod privleges in sudoers this user wouldn't have a password then i'd use php exec function to chmod the permission on the file. Link to comment https://forums.phpfreaks.com/topic/166300-chmod-major-help-needed-permission-from-0600-to-064/#findComment-877724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.