- Forums
- PHP
- How To Show All Files That Are Contained In A Directory With Php
This Page Contains information about How To Show All Files That Are Contained In A Directory With Php By wallpaperama in category PHP with 0 Replies. [1244], Last Updated: Sat May 18, 2024
wallpaperama
Fri Jan 23, 2009
0 Comments
343 Visits
today i wanted to know how i can list all the files in a directory i have in my php website. well, if you are wondering how you can Display a list of files in a directory by using php code, you can use the readdir() function from php. when you use the readdir function is will get and shows all the files that are in a folder or directories. for example, lets say i have a directory with many file in it and i want to displays a list of all the files in the current dirtory that have these files:
lets say i have a directory called includes and i want to find all the files in the includes directory and it has all these files inside:
./includes
database.php
functions.php
constantts.php
wallpaperama.gif
wallpapers.php
countdown.js
as you can see i have many files in the includes/ directory and if i want to i just have to create an index.php file inside the includes directory and the index.php file will show all of them. try it. here is the code i use. all you have to do is open your text editor like notepad, then copy and paste this code and save it as index.php and upload to the directory where you want to show all the files in your browser.
PHP CODE: index.php
<div style="background-color:#FFC; height:27px; padding:2px">Learn More About PHP at <a href="http://www.wallpaperama.com/">Wallpaperama.com</a> | PHP Hosting Provided by <a href="http://www.webune.com/">Webune</a></div>
<hr><?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo '<a href="'.$file.'">'.$file.'</a></br>';
}
}
closedir($handle);
}
?>