php PHP函数重命名权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11773708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:02:56  来源:igfitidea点击:

PHP Function Rename Permission denied

phppermissionsrename

提问by wyy

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.

在服务器中,脚本创建新文件夹,将 chmod 设置为 0777,但随后它尝试将文件移动到该文件夹​​,我收到错误:权限被拒绝。

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

警告:rename(files/new_file.jpg,../112a/112b/Tech_diz_1.jpg) [function.rename]:第 82 行的 ..code/Jpg&Html.php 中的权限被拒绝

Any solutions?

任何解决方案?

回答by oezi

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.

仅拥有目标文件夹的权限是不够的,因为文件已从其源中删除。

回答by bkwint

You should also have permission to change the file "files/".$failai[$i].".jpg". I would guess that that is going wrong

您还应该具有更改文件的权限"files/".$failai[$i].".jpg"。我猜那是错误的

回答by Praveen Kumar Purushothaman

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

你有文件的写权限吗?如果没有,请确保您chmod的文件为777或至少为644.

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

此外,file_exists()在重命名之前,通过在文件名上给出 a来检查文件是否存在。:)

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:

此外,移动文件后,您可能需要设置权限chmod()以使其可用于重命名。你可以这样做:

<?php
    chmod($uploadedFile, 0755);
?>