cory011202 Posted August 19, 2008 Share Posted August 19, 2008 Hello all, I am fairly new to php and I am trying to create an array from files listed in a directory such as images. Below is my code so far. I would like to take the results and put them into an array that I can display on a page. In the end I will have the images change every hour from top to bottom (that is the plan atleast). Any help or direction anyone can give would be greatly appreciated. I hope I have posted this in the correct forum topic. Thanks in advance. <?php $open = opendir("./test/"); while ($read = readdir($open)) { if ($read!= "." && $read!= "..") { echo $read . '<br>'; } } closedir($open); ?> Quote Link to comment https://forums.phpfreaks.com/topic/120358-solved-creating-an-array-from-files-in-a-directory/ Share on other sites More sharing options...
Fadion Posted August 19, 2008 Share Posted August 19, 2008 Try <?php $files = array(); $dir = '/test'; while($file = readdir($dir)){ if($file != '.' and $files != '..'){ $files[] = $file; } } closedir($dir); print_r($files); //show the contents of $files array ?> or alternatively you can use glob(): <?php $files = array(); foreach(glob('/test/*.jpg') as $file){ $files[] = $file; } print_r($files); ?> Hope that helps and if you have anymore questions, feel free to ask. Quote Link to comment https://forums.phpfreaks.com/topic/120358-solved-creating-an-array-from-files-in-a-directory/#findComment-620106 Share on other sites More sharing options...
cory011202 Posted August 20, 2008 Author Share Posted August 20, 2008 Thank you as this was able to do exactly what I needed thank you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/120358-solved-creating-an-array-from-files-in-a-directory/#findComment-620653 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.