PDA

View Full Version : File permissions on upload


MikoLone
06-21-2007, 04:32 AM
I am uploading picture. This is part of the code


if(!move_uploaded_file($_FILES['fullSizePic'.$propId.$i]['tmp_name'], '../images/properties/'.$imageName) ){
chmod('../images/properties/' . $imageName , 0777);
}


The file uploads and moves into the properties folder. That folder's chmod is 777, but the file's chmod is only 600 making it unreadable by the server. I try to chmod it with php (as you can see above) and it doesn't work.

Any suggestions?

Thanks

MikoLone
06-21-2007, 04:43 AM
Sorry guys.

I found the problem. I am totally rolling my eyes at myself.

I changed my code to this


if(!move_uploaded_file($_FILES['fullSizePic'.$propId.$i]['tmp_name'], '../images/properties/'.$imageName) ){

}
chmod('../images/properties/' . $imageName , 0777);



and it worked.

If anyone can tell me why that would be great. Why wouldn't it work inside the if statement???

_Aerospace_Eng_
06-21-2007, 05:04 AM
Because you say if the file isn't moved meaning something went wrong. If it uploaded properly then that if statement is never true so that chmod won't occur. You should probably put the chmod at the beginning of your file or better yet chmod the folder using an ftp program.

MikoLone
06-21-2007, 08:31 PM
See that is the weird part. I sshed into the server and chmoded the folder to 777 but it was still writing the files as 600.

That was dumb of me. I should have realized it was if it didn't move correctly.

I am still rolling my eyes at myself but even moreso now.

Thanks for the reply.