0

提取后删除服务器中的目录时遇到问题。

我已经将 file.zip 上传到服务器,然后创建了一个名为“ en ”的文件,授予它777权限,然后将 file.zip 的内容提取到“ en ”,就可以了。问题是,我现在无法删除en ”下的任何文件,但是,重命名似乎可以正常工作。我能够将“en”重命名为“delete_me”,并且也能够将其重命名为子目录。

如果我尝试删除“delete_me”下的单个文件,例如 index.html,我会得到

Command:    DELE index.html
Response:   550 index.html: Permission denied

1- FTP 删除尝试:

当我尝试通过 FTP - FileZilla 删除“delete_me”时,它开始在目录中循环并为每个文件显示以下消息:

Response:   150 Opening BINARY mode data connection for MLSD
Response:   226 Transfer complete
Status: Directory listing successful
Command:    DELE index.html
Response:   550 index.html: Permission denied
Command:    CWD /httpdocs/_delete_me
Response:   250 CWD command successful

当我检查(所有者/组)时,我发现它是(48/48),而我创建的其他目录或文件有(10618/2524)。

2- cPanel 删除尝试:

我尝试通过托管控制面板文件管理器进行访问,然后发现“delete_me”中的文件夹的(用户/组)是( apache/apache,而对于我的文件(/psacln

当我尝试从主机控制面板中删除文件时,我得到

Error: Unable to remove file /httpdocs/_delete_me// var/www/vhosts/<hostname>/httpdocs/_delete_me/tmp: filemng failed: rm: cannot remove `/var/www/vhosts/<hostname>/httpdocs/_delete_me/tmp/index.html': Permission denied
filemng: Error occured during /bin/rm command.

3- PHP删除:

最后一件事我试图更改权限@chmod($dirPath, 0777);并删除rmdir($dirPath);unlink($file);但没有结果。

与我的问题相似的唯一资源是here(论坛问题),但似乎没有得到解答(提供的答案链接不再可用)。

**那么,如何删除文件?**

4

1 回答 1

1

您必须 chmod 该目录中的所有内容。

尝试这个

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathname));

$filemode = "0777"; // Set the permission

// Foreach item found set the permissions
foreach($iterator as $item) {
    chmod($item, $filemode);
}

如果您要rmdir($dirPath);确保首先从目录中删除所有文件,否则我相信它将无法删除目录。

当然,unlink($filepath);一旦权限设置为正确的权限,删除文件使用将起作用。

于 2014-11-18T16:26:31.023 回答