Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Function Rename Permission denied

In server, script create new folder, set chmod to 0777, but then it tryes to move files to that folder i get error: Permission denied.

mkdir("../".$new_1, 0777);
chmod("../".$new_1, 0777);

mkdir("../".$new_1."/".$new_2, 0777);
chmod("../".$new_1."/".$new_2, 0777);

rename("files/".$failai[$i].".jpg", "../".$new_1.'/'.$new_2."/".$failai[$i].".jpg");

Warning: rename(files/new_file.jpg,../112a/112b/Tech_diz_1.jpg) [function.rename]: Permission denied in ..code/Jpg&Html.php on line 82

Any solutions?

like image 564
wyy Avatar asked Aug 02 '12 08:08

wyy


2 Answers

you'll need to have read and write permissions in the source folder, too.

only having permissions for the target-folder isn't enough as the file is removed from it's source.

like image 86
oezi Avatar answered Nov 13 '22 00:11

oezi


Do you have the write access to the file? If not, make sure you chmod the file to 777 or at least to 644.

Also, check the existence of the file by giving a file_exists() on the file name before you rename. :)

Also, after moving file, you might need to set the permissions using chmod() to make it available for renaming. You can do it this way:

<?php
    chmod($uploadedFile, 0755);
?>
like image 1
Praveen Kumar Purushothaman Avatar answered Nov 12 '22 22:11

Praveen Kumar Purushothaman