zfred09 Posted May 6, 2007 Share Posted May 6, 2007 I am using this bit of code to get all the images from a directory into an array, how would I add the name of a folder/directory into the array also? $list = glob("*.jpeg"); Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/ Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 6, 2007 Share Posted May 6, 2007 Can you use regular expressions? Like say...."find instances where filename does NOT contain a period"....thus implying that it's a folder... $list = glob("(!.|*.jpeg)"); or, do it twice...but with the 2nd time, using only directories... $list = glob("*.jpeg"); $list2 = glob("*", GLOB_ONLYDIR); Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246815 Share on other sites More sharing options...
zfred09 Posted May 6, 2007 Author Share Posted May 6, 2007 Not sure if Regex work with the glob function or not, but I put it in and nothing got selected. Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246816 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 6, 2007 Share Posted May 6, 2007 Did you try my 2nd option? Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246823 Share on other sites More sharing options...
zfred09 Posted May 6, 2007 Author Share Posted May 6, 2007 That works for selecting directories, now how would I put both the images and directory in the same array? Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246828 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 6, 2007 Share Posted May 6, 2007 foreach($array2 as $item) { $array1[] = $item; } Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246829 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 6, 2007 Share Posted May 6, 2007 or, I just found this function lying around.... $newArray = array_merge($array1, $array2, $array3); Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246842 Share on other sites More sharing options...
neel_basu Posted May 7, 2007 Share Posted May 7, 2007 It will work <?php $dir = "/path/to/dir/"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(getimagesize($file)){ $image_array[] = $file; } } closedir($dh); } } print_r($image_array); ?>Here getimagesize() is making sure weather its an Image file or not. Sorry cannot use [ php ][ / php ] here Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-247001 Share on other sites More sharing options...
boo_lolly Posted May 7, 2007 Share Posted May 7, 2007 scandir(), readdir(), opendir(). Link to comment https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-247013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.