PHP upload permission problem

exchange-love

New Member
right guys ive ran into a problem with file permissions with the following upload form. a text file is passed to the upload/ dir by global users.\[code\]mysite$ ls -ldrwxrwxrwx 2 user user 4096 2010-09-24 13:07 upload\[/code\]but as I am not logged in as root, the new file uploaded to the domain saved itself in the upload/ dir with limiting permissions and cannot be modified. eg. \[code\]upload$ ls -l-rw-r--r-- 1 www-data www-data 3067 2010-09-24 13:07 Readme.txt\[/code\]this problem is obviously the same for all files added to the upload folder by global users. once the file is uploaded I need a way of changing the file rights without embedding the root password into a php script running on the domain. please help!is there any way to associate the same rights to files as the containing folder when new files are added?submit form:\[code\]<html><body><form action="upload_file.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file" /> <br /><input type="submit" name="submit" value="http://stackoverflow.com/questions/3787680/Submit" /></form></body></html>\[/code\]upload_file.php:\[code\]<?phpif ($_FILES["file"]["type"] == "text/plain") { 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("/home/user/mysite/upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "/home/user/mysite/upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } }else { echo "Invalid file"; }?>\[/code\]
 
Back
Top