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.

Member Avatar for iamthwee

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.

Member Avatar for iamthwee

Google the php api.

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

Just make sure the permissions are set appropriately.

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');
?>
commented: Thanks This Script Worked +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.