Deleting A directory

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I have been working on a software package. All the install files are in a folder called install. When the installation is finished they are forwarded to a file called delete_install.php which is in the install folder. I have been trying to figure out how to delete the install folder and all files in it. I found the code below but im unsure if it will work properly.

Code:
<?php
$dirname = './install';

if (is_dir($dirname))
    $dir_handle = opendir($dirname);
if (!$dir_handle)
    return false;
while($file = readdir($dir_handle)) {
    if ($file != "." && $file != "..") {
        if (!is_dir($dirname."/".$file))
          unlink($dirname."/".$file);
        else
          delete_directory($dirname.'/'.$file);          
    }
}
closedir($dir_handle);
rmdir($dirname);
return true;

?>

Will this work or do I need to do something else. Thanks in advance.
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
This looks like it will work correctly, but I am unsure if you are able to delete the script being executed. You will probably have to have the file outside of the install directory, or create a temporary uninstall file from the script. Also the 'return true' is only used like that for included files, or functions. As it is I believe you would receive an error.

Run it and tell us what happens :)
 
Last edited:

nirajkum

New Member
Messages
159
Reaction score
0
Points
0
the code seems to be okie ... u need not to worry about that please make sure you delete install.php properly
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
The first line, $dirname, is a wrong value. How you presented it, the $dirname points to the /install/install directory.
Put two dots instead of one, this should change the directory.
 
Last edited:
Top