To count the files displayed

December 4, 2022 · View on GitHub

Filtered Directory Display

Description

This Code can be used to display files that reside in a diredtory on your web server. This example uses regular expression to achieve the filter affect, you can set to show only Php file, or every thing but php. The way you use this script is up to you. The Script was commented where i felt it was needed, i hope you like it. Also vote to make me happy :)

More Info

Submitted On
Bytehfatal
LevelBeginner
User Rating5.0 (25 globes from 5 users)
CompatibilityPHP 3.0, PHP 4.0
CategoryFiles
WorldPHP
Archive File

API Declarations

http://fatal.pr3p.com
itz_fatal@hotmail.com

Source Code

<?php
# To count the files displayed
$count = 0;
# open the directory you want to use
$directory = opendir(".");
# Gather the files, and put them in a array
while( $file = readdir( $directory ) )
{
$file_array[] = $file;
}
# Blockquote used for displaying purposes
echo"<blockquote><br>";
# Tell php if it finds a directory to
# skip over it
foreach( $file_array as $file )
{
if( $file == ".." || $file == "." )
{
continue;
}
# Regular expression statement to only echo
# back files with a .php extendtion
# the '.php$' tells the Regular expression statement to
# only return files with the .php extendion at the end
if( !ereg( ".php$", $file ) )
{
continue;
}
# Display the file with a link
echo"<font face=\"Tahoma\" size=\"2\">• <a href=\"\php/$file\">$file</a></font><br>";
# Count the file that was displayed
$count++;
}
echo"</blockquote>";
# Display Number of files that were displayed
echo"<font face=\"Tahoma\" size=\"2\">There are <b>$count</b> valid Php Files In the Test Directory</font>";
#close thedirectory you used
closedir($directory);
?>