Jump to content

Recommended Posts

You need to recursively delete the contents of the directory, before you can delete it. There's plenty of functions/snippets to search for through Google that should help you there. As vicodin suggested, you may run into permission issues as well.

i have tryed the below but i get 2 errors

<?php
$path = "../../gallery2.0/gallery_files/gallery/";
if(isset($_POST['file']) && is_array($_POST['file']))
{
foreach($_POST['file'] as $file)
{	
	$mydir = $path.$file; 
$d = dir($mydir); 
while($entry = $d->read()) { 
if ($entry!= "." && $entry!= "..") { 
unlink($entry); 
} 
} 
$d->close(); 
rmdir($mydir);
}

}
?>

 

these are the errors  the folder it is trying to delete is folder1 and the contents is just a picture called pic1.jpg but the errors say the picture isn't there but it is because it is picking its name up and the seconds says the folder is not empty.

 

Warning: unlink(pic1.jpg) [function.unlink]: No such file or directory in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 63

 

Warning: rmdir(../../gallery2.0/gallery_files/gallery/Folder1) [function.rmdir]: Directory not empty in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 67

You need to use a recursive function for this. Theoretically that sub-directory could contain a sub-directory, which contains a sub-directory, which contains a sub-directory, etc. You need to remove the contents of each before you can delete it. Rather than nesting loops within loops, just use a function that will repeatedly (recursively) call itself. I provided a Google link earlier that should help you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.