Forum Moderators: coopster

Message Too Old, No Replies

How do I chmod a file upload with PHP

Need to modify file permissions on upload

         

russkern

12:01 am on Sep 12, 2007 (gmt 0)

10+ Year Member



I need to change the file permissions on file uploads through my PHP form from 600 to 644 so they can be viewed in a website.

what is the correct way to do this?

My current code snippet looks like:

$upload_dir = "uploads/";
$filename = $upload_dir.$_FILES['upload']['name'];
chmod($filename, 0644);
if(move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/{$_FILES['upload']['name']}")) {

etc...

Help would be appreciated...

eelixduppy

12:26 am on Sep 12, 2007 (gmt 0)



You have to change the permissions after the file has been uploaded so you have to use chmod() after move_uploaded_file(), not before.

russkern

12:31 am on Sep 12, 2007 (gmt 0)

10+ Year Member



Perfect... Thank you..

that would have been easy to troubleshoot via trial and error :)

Thanks again