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.


<?php

$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
print_r($list_files);
echo '</pre>';

/*
Output look like this

Array
(
[0] => .
[1] => ..
[2] => TextDocument.txt
[3] => kuppiya.doc
[4] => lion.ppt
[5] => test.as
)

*/

?>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

No comments:

Post a Comment