0

Hi, I need a script that on click of a button. Delete a folder/file.

So when I click the button the folder deletes and it is for a install file that I made.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by vibhaJ
0

Google the php api...

Then it should be just a case of your button sending the name of the file and deleting it with php.

0

Google the php api.

There should be functions to delete or remove a directory/file.

Just make sure the permissions are set appropriately.

1

From Google...

<?php
// ------------------------------------------------------------
function recursive_remove_directory($directory, $empty=FALSE)
{
    if(substr($directory,-1) == '/')
    {
        $directory = substr($directory,0,-1);
    }
    if(!file_exists($directory) || !is_dir($directory))
    {
        return FALSE;
    }elseif(is_readable($directory))
    {
        $handle = opendir($directory);
        while (FALSE !== ($item = readdir($handle)))
        {
            if($item != '.' && $item != '..')
            {
                $path = $directory.'/'.$item;
                if(is_dir($path)) 
                {
                    recursive_remove_directory($path);
                }else{
                    unlink($path);
                }
            }
        }
        closedir($handle);
        if($empty == FALSE)
        {
            if(!rmdir($directory))
            {
                return FALSE;
            }
        }
    }
    return TRUE;
}
// ------------------------------------------------------------
recursive_remove_directory('install');
?>
Votes + Comments
Thanks This Script Worked
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.