Exemple #1
0
/**
 * Delete a file, or a folder and its contents (recursive algorithm)
 *
 * @author      Aidan Lister <*****@*****.**>
 * @version     1.0.3
 * @link        http://aidanlister.com/2004/04/recursively-deleting-a-folder-in-php/
 * @param       string   $dirname    Directory to delete
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function rmdir_and_contents($dirname)
{
    // Sanity check
    if (!file_exists($dirname)) {
        return false;
    }
    // Simple delete for a file
    if (is_file($dirname) || is_link($dirname)) {
        return unlink($dirname);
    }
    // Loop through the folder
    $dir = dir($dirname);
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Recurse
        rmdir_and_contents($dirname . DIRECTORY_SEPARATOR . $entry);
    }
    // Clean up
    $dir->close();
    return rmdir($dirname);
}
Exemple #2
0
function clear_database()
{
    $folds = array_diff(scandir("database/users"), array('.', '..'));
    foreach ($folds as $item) {
        rmdir_and_contents("database/users/{$item}");
    }
    $tasks = array_diff(scandir("database/done"), array('.', '..'));
    foreach ($tasks as $item) {
        unlink("database/done/{$item}");
    }
    $tasks = array_diff(scandir("database/wip"), array('.', '..'));
    foreach ($tasks as $item) {
        unlink("database/wip/{$item}");
    }
    $tasks = array_diff(scandir("database/dead"), array('.', '..'));
    foreach ($tasks as $item) {
        unlink("database/dead/{$item}");
    }
    $tasks = array_diff(scandir("database/todo"), array('.', '..'));
    foreach ($tasks as $item) {
        unlink("database/todo/{$item}");
    }
    unlink("database/email");
    unlink("database/passwd");
    touch("database/email");
    touch("database/passwd");
    unlink("database/config");
    $file = fopen("database/config", "w");
    fprintf($file, "1\n");
    fclose($file);
    registerUser("root", "root@admin", "azertyuiop", "@68s?qed");
}
Exemple #3
0
 function delete_file_storage_for_row_and_col($row_id, $col_id)
 {
     rmdir_and_contents($this->get_thor_filestorage_row_and_col_specific_storage_dir($row_id, $col_id));
 }