Question

i have file in upload/project1/update.

the problem is,only files in update is deleted. i want to remove the directory in folder upload...thats mean,folder name 'project1' and 'update' also delete after the files in update is deleted.can u spots the mistakes for me??

$id = $_GET['id'];
$filename = $_GET['filename']; //gets the file name eg:update.zip
$fname = $_GET['fname']; //gets the folder name eg: project1
$upload = "upload/";

$name = explode(".", $filename);
$folder = $fname."/".$name[0];

$files = glob($upload.$folder.'/*'); // get all file names
foreach($files as $file)
{ // iterate files
if(is_file($file))
 unlink($file); // delete file dlm folder

}

closedir($name[0]); //close update dir
rmdir($name[0]); //remove update dir

this coding give warning

Warning: closedir() expects parameter 1 to be resource,

Warning: rmdir(update) [function.rmdir]: No such file or directory..

but in the directory upload,have this file project1/update.

also,the filename is 'update.zip' is just the name in database only..not in the directory.

Was it helpful?

Solution

You cannot closedir() on a directory that has not previously been opened (and stored in a filehandle) with the opendir() PHP function. If you want to closedir() you will need to get a filehandle to this directory first using opendir(). This is per the PHP manual: http://php.net/manual/en/function.closedir.php

Additionally, if you want to rmdir() a directory, it needs to be completely empty and you need the appropriate permissions. Otherwise, you will get errors. This is also per the PHP manual: http://php.net/manual/en/function.rmdir.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top