Posts tagged Directory

Directory Lister

<?

/*

Change the path to your folder.

This must be the full path from the root of your
web space. If you’re not sure what it is, ask your host.

Name this file index.php and place in the directory.

*/

// Define the full path to your folder from root
$path = “/home/user/public/foldername/”;

// Open the folder
$dir_handle = @opendir($path) or die(“Unable to open $path”);

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == “.” || $file == “..” || $file == “index.php” )

continue;
echo “<a href=\”$file\”>$file</a><br />”;

}

// Close
closedir($dir_handle);

?>

Leave a comment »

Remove Directory

<?php

$mypath = "mambo";

function rmdirr($dirname)
{
    // Sanity check
    if (!file_exists($dirname)) {
        return false;
    }
 
    // Simple delete for a file
    if (is_file($dirname)) {
        return unlink($dirname);
    }
 
    // Loop through the folder
    $dir = dir($dirname);
    while (false !== $entry = $dir->read()) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
 
        // Recurse
        rmdirr("$dirname/$entry");
    }
 
    // Clean up
    $dir->close();
    return rmdir($dirname);
}

rmdirr("$mypath");
 
?>

Comments (2) »