Folder delete error - can't delete folders extracted from zip

2.8k views Asked by At

I'm having an issue deleting a directory in the server after it was extracted.

I've uploaded file.zip to the server, then created a file called "en", gave it permission 777 then extracted the content of file.zip to "en" and it was ok. The thing is, I cannot now delete any file under "en" however, renaming seems to work fine. I was able to rename "en" to "delete_me" and was able to rename it's sub dir as well.

If I try to delete a single file under "delete_me" for example index.html, I get

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

1- FTP delete attempt:

When I try to delete "delete_me" via FTP - FileZilla, it starts looping inside the dir and showing this message for each file:

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

When I checked the (owner/group), I found it's (48/48) while other dir or files created by me have (10618/2524).

2- cPanel delete attempt:

I tried the to access via the hosting control panel File Manager then found the (User/Group) for folders inside "delete_me" is (apache/apache while for my files (/psacln)

When I try to delete the file from the hosting control panel, I get

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 Delete:

Last thing I tried to change permission @chmod($dirPath, 0777); and delete rmdir($dirPath); or unlink($file); but without a result.

The only resource found similar to my issue is here (Forum Question) but it seems it wasn't answered (answer link provided is no longer available).

**So, how to delete the file? **

1

There are 1 answers

4
AudioBubble On

You'll have to chmod everything in that directory.

try this

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

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

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

if you're going to do rmdir($dirPath); be sure to remove all of the files from the directory first, otherwise I believe it will fail to remove the directory.

And of course to remove files using unlink($filepath); will work once the permissions have been set to the correct ones.