View Full Version : how to explore a directory with the php

05-30-2010, 08:57 AM
today we will know how to know the content of any folder with the php with a simple code
first you should download this simple class (http://www.jooria.com/projects/view?project=989&m=downloads)

then we can use it for that
just include it

require_once ('readDir.class.php'); and start new one
then you have to set the path of your folder

if (!$dir->setPath( $base_dir.'/example' )) {
know if you want to make the system going on any sub folder just use

and you can use the call back system in the class just like that

// set a function to call when a new dir is read
if (!$dir->setEvent( 'readDir_dir', 'my_dir_function' )) { ;
// set a function to call when a new file is read
if (!$dir->setEvent( 'readDir_file', 'my_file_function' )) {

you can see the example:example.php (http://www.jooria.com/view/file/511/example.php)
and you can make the system stoping at a specifice point just like that

if ($filename == 'secret_php_file.php') {
echo 'We found the file we are looking for. Stopping directory read.<br />';

return -1; // return negative 1 to stop the reading of the directory

05-30-2010, 02:22 PM
as of PHP5 PHP has built-in classes for this , see http://au.php.net/recursivedirectoryiterator

05-30-2010, 03:36 PM
oh great this the first time i konw that
thank u