hanhao Posted June 1, 2006 Share Posted June 1, 2006 generating an array which contains filenames of a dirok i have this dir called "images"in it contain .jpg and .txt filessomething like:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]abc.txtdef.txtqwe.jpgkwe.jpg[/quote]now what i need to do is to enter .jpg only into my array such that the resultant array isarray_of_jpg_filenames[0] = qwe.jpgarray_of_jpg_filenames[1] = kwe.jpganyone knows how can i do that?thanks Quote Link to comment https://forums.phpfreaks.com/topic/10933-generating-an-array-which-contains-filenames-of-a-dir/ Share on other sites More sharing options...
hanhao Posted June 1, 2006 Author Share Posted June 1, 2006 [!--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 dirok i have this dir called "images"in it contain .jpg and .txt filessomething like:now what i need to do is to enter .jpg only into my array such that the resultant array isarray_of_jpg_filenames[0] = qwe.jpgarray_of_jpg_filenames[1] = kwe.jpganyone knows how can i do that?thanks[/quote]thnx for helpthis 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] Quote Link to comment https://forums.phpfreaks.com/topic/10933-generating-an-array-which-contains-filenames-of-a-dir/#findComment-40830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.