VB icon

Filtered Directory Display

Email
Submitted on: 1/1/2015 8:48:00 AM
By: tehfatal (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 723
 
     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 :)
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Filtered Directory Display
//**************************************
http://fatal.pr3p.com
itz_fatal@hotmail.com
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: 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 :)
// By: tehfatal (from psc cd)
//**************************************

<?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);	
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.