ander Posted July 28, 2008 Share Posted July 28, 2008 I have a script (in a CMS) that uploads files to a server (PDFs, images and such), and it works fine for getting the files up there. But now I've noticed a problem when trying to download files through FTP - I get 'permission denied'. I can access the files fine on the site through a browser, but the permissions problem makes it impossible for us to download a bunch of our files at once through FTP. I assume this has something to do with the owner of the file being set improperly in my upload script, to something that doesn't correspond with the FTP login credentials. I don't know a lot about this stuff, can anyone tell me what I need to add to the script to set the proper permissions? script excerpt below, uploads file to 'files' folder and puts an entry in a database with a description of the files and where to find it: //pulls info from form on previous page, this is all in a for loop by the way, multiple files can be uploaded in the form $filename= basename($_FILES['uploadedfile']['name'][$i]); $description= $desc[$i]; //sets the file type, just for database purposes if ($filename) { $type= substr("$filename", -4); if ($type == ".jpg" || $type == ".gif" ) { $type= "image"; } elseif ($type == ".pdf") { $type= "PDF"; } elseif ($type == ".doc") { $type= "document"; } elseif ($type == ".htm" || $type == "html" ) { $type= "HTML"; } else { $type= "other: " . $type; } //this line uploads the file, really the important line for this problem i think if (move_uploaded_file ($_FILES['uploadedfile']['tmp_name'][$i], "../files/{$_FILES['uploadedfile']['name'][$i]}")) { //if successful, an entry for the file is created in the database $addFile="INSERT INTO tblFiles (fileName, description, type) VALUES ('$filename', '$description', '$type')"; mysql_query($addFile, $db); //confirmation back to the user about the uploaded file echo "<p style=\"font-size: 11pt\">Your file, <b>$description <i>($filename)</i></b>, was uploaded successfully. The link to your file is:</p><p align=\"center\"><a href=\"../files/$filename\">www.aclutx.org/files/$filename</a></p><hr>\n"; } Additional weirdness: The permissions thing is only a problem for some of the files, while some download in FTP fine. wtf? Thanks so much to anyone who can help! Link to comment https://forums.phpfreaks.com/topic/117040-permissions-problem-for-files-uploaded-with-php/ Share on other sites More sharing options...
discomatt Posted July 28, 2008 Share Posted July 28, 2008 The files will be created via the user running PHP/Apache, you'll have to CHMOD the files to give your FTP user permission. http://php.net/manual/en/function.chmod.php Link to comment https://forums.phpfreaks.com/topic/117040-permissions-problem-for-files-uploaded-with-php/#findComment-601997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.