how to index files in a folder using php


I had found a source code that can index files in a folder and display it to you. here is the code

<ul>
 <?php
 // Define the full path to your folder from root
 $dir = "C:/xampp/htdocs/IRS/dataset/medDATA/med";
 if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
 while (($file = readdir($dh)) !== false) {
 if($file == "." || $file == ".." || $file == "index.php"){
 continue;
 }
 print "<li><a href='".($dir.$file)."'>{$file}</a></li>";
 }
 closedir($dh);
 }else{
 print "Error: Could not open directory {$dir}";
 }
 }else{
 print "Error: '{$dir}' is not a directory";
 }
 ?>
 </ul>

so what you need to do is that you just need to specify the folder which you want the code to index and the code will display all the files for you. 🙂

happy programming with php then. 😛

Advertisements

One comment on “how to index files in a folder using php

  1. […] how to index files in a folder using php « Jacobian […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s