Jump to content

Archived

This topic is now archived and is closed to further replies.

hanhao

generating an array which contains filenames of a dir

Recommended Posts

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=378975:date=Jun 1 2006, 02:41 AM:name=hanhao)--][div class=\'quotetop\']QUOTE(hanhao @ Jun 1 2006, 02:41 AM) [snapback]378975[/snapback][/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

[code=php:0]
<?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);
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.