Jump to content

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
[!--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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.