This is the code you need...
- Code: Select all
<?
// Name of this file
$thisfile = "imagebrowse.php";
echo "<h1>Directory Listing</h1>\n";
$count == "1";
// The directory our files (images) are stored in
$images_directory = opendir("../images/");
// Setup a loop to link through all the files in the directory
while($filename = readdir($images_directory))
{
// We need to eliminate this file (if it's in the same directory)
// along with . and .. (this dir and go up a dir)
if ($filename == $thisfile OR $filename == "." OR $filename == "..") {
}
else {
// All these others are files
echo("
<a href=\"http://$fullurl/admin/images/$filename\" target=\"_blank\">$filename</a>\n");
$count=substr_count($filename,".");
if ($count == "1" && $filename != ".") {
if (isset($showimages)) {
echo "
<img src=\"http://$fullurl/admin/images/$filename\">
\n";
}
echo "";
echo(filesize($filename));
echo(" Bytes
\n");
}
else {
}
}
$count++;
}
closedir($images_directory);
?>
That will show the text names and file sizes of all files in that particular directory specified.
Also bear in mind that I used a variable $fullurl which isn't declared in the code. Replace it or declare it for yourself.
Obviously you can tweak the code so that it displays the actual images, or whatever you like.
It's also possible to filter files by their extension, but I'll let you try to figure that our for yourself first.