PDA

View Full Version : php Listing contents in the directory


heracleitus_16
09-10-2005, 05:51 AM
Sometimes we need to list contents in the diectory.
Here is a sample where you can list the files inside the folder.
You can also specify what files to list and not to list.
The below will list ZIP files.

Create a file called "list.php"
and enter the following

<?php
// List and store ZIP files names
exec ("ls -d *.zip", $output, $return);

// Find the specific ZIP file and remove from array
$secret_file = array_search('secret.zip', $output);
unset ($output["$secret_file"]);

// Count the number of Files that we have
$totaldir = count($output);
print "We have $totaldir Files for download<br>";
print "Click on the Foile name below to Vstart your downlaod<br><br>";

// List Forums if directory can be opened
if ($return == "0")
{
foreach ( $output as $file )
{
print ("<a href='http://domain.com/$file'>$file</a><br>");
}
}

// If the directory can't be opened print the error message
else
{
print "There is an error in the loading of the directory contents<br>";
}
?>