Jump to content


Photo

generating an array which contains filenames of a dir


  • Please log in to reply
1 reply to this topic

#1 hanhao

hanhao
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 01 June 2006 - 07:41 AM

generating an array which contains filenames of a dir


ok i have this dir called "images"
in it contain .jpg and .txt files

something like:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]abc.txt
def.txt
qwe.jpg
kwe.jpg[/quote]

now what i need to do is to enter .jpg only into my array such that the resultant array is

array_of_jpg_filenames[0] = qwe.jpg
array_of_jpg_filenames[1] = kwe.jpg

anyone knows how can i do that?
thanks

#2 hanhao

hanhao
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 01 June 2006 - 08:13 AM

[!--quoteo(post=378975:date=Jun 1 2006, 02:41 AM:name=hanhao)--][div class=\'quotetop\']QUOTE(hanhao @ Jun 1 2006, 02:41 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
generating an array which contains filenames of a dir
ok i have this dir called "images"
in it contain .jpg and .txt files

something like:
now what i need to do is to enter .jpg only into my array such that the resultant array is

array_of_jpg_filenames[0] = qwe.jpg
array_of_jpg_filenames[1] = kwe.jpg

anyone knows how can i do that?
thanks
[/quote]


thnx for help

this is the solution

<?php
$dh = opendir($folder); 
if(!$dh) { 
	exit('Open dir function failed!'); 
} 
          
$file_array = array(); 
while (($file = readdir($dh)) !== false ){ 
	if ($file != "." && $file != ".."){
		$bits = explode(".", $file);
		if($bits[1] == "jpg"){
			$file_array[] = $file;
		}
  } 
}
print_r($file_array);
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users