Monday, November 10, 2008

How to search/scan files inside a directory using php - scandir()

Lets see how we can scan or search files inside a directory using php. You can use scandir() for this matter. scandir() will go through the given directory and return all the files in an array.


$dir_path = 'kusal/test'; //directory path
$list_files = scandir($dir_path);

//dumping the array
//hope you know how to access an array
echo '<pre>'; //html <pre> tags will format the output
echo '</pre>';

Output look like this

[0] => .
[1] => ..
[2] => TextDocument.txt
[3] => kuppiya.doc
[4] => lion.ppt
[5] =>



Get Free Sinhala IT Learning Videos

Get custom programming done at!

No comments:

Post a Comment