You are here: Find all files in a directory « All PHP « IT news, forums, messages
Find all files in a directory

Posted by Aquosus on 10/06/06 05:05

I am trying to load all the images from the Images directory. There are
about six sub_Directories in the Images directory. Some of the Sub_Dir have
Subs themselves.

I have tried to write the following but it seems to not work at all.

I know there must be a simple way to do this and I don't feel like
re-inventing the wheel. Could someone show me some code that will read the
directory and its Sub_Directories seeking for all JPEGs.

Thanks

//Snippet


$dir = "/Images/";

$myDirArray=array();

if(is_dir($dir))
{
if($dh=opendir($dir))
{
while(($file=readdir($dh))!==false)
{
$tmpDir=$dir . $file;
if(is_dir($tmpDir))
{
if($myDir=opendir($tmpDir))
{
while($myFile=readdir($myDir))
{
array_push($myDirArray, $tmpDir.$myFile);
}//while($myFile=readdir($myDir))
closedir($myDir);
}//if($myDir=opendir($tmpDir))
}//if(is_dir($tmpDir))
}//while(($file=readdir($dh))!==false)
closedir($dh);
}//if($dh=opendir($dir))

for($x=0;$x<sizeof($myDirArray);$x++)
{
echo "Corrected filename: $myDirArray[$x] <BR />\n<BR />\n";
}//for($x=0;$x<sizeof($myDirArray);$x++)

}//if(is_dir($dir))

end Snippet//
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация