neridaj Posted February 11, 2008 Share Posted February 11, 2008 Hello, I have a user registration page that builds a directory named "username" upon successful registration. This directory is then populated with photos for the user to download upon successful login. I would like to know how I can loop through this directory to build and populate a table with all the photos inside of it by grabbing any .jpg file type. I'm assuming I would use some regular expression to grab the .jpg files, but I'm not sure how to loop through a directory to accomplish this. If anyone can help me with this I would really appreciate it. Thanks, Jason Link to comment https://forums.phpfreaks.com/topic/90464-looping-through-image-directory/ Share on other sites More sharing options...
Wolphie Posted February 11, 2008 Share Posted February 11, 2008 <?php $dir = dir('username'); while(($file = $dir->read()) !== false) { if(preg_match('^([%\w-]+\.(?:jpe?g¦JPE?G¦gif¦GIF¦png¦PNG)¦)$', $file)) { echo 'Image found!'; } } $dir->close(); ?> I suck at regular expressions so don't count on it! Link to comment https://forums.phpfreaks.com/topic/90464-looping-through-image-directory/#findComment-463793 Share on other sites More sharing options...
neridaj Posted February 11, 2008 Author Share Posted February 11, 2008 I tried that and got this: Fatal error: Call to a member function read() on a non-object So I then tried this and an array listing the only the "." and ".." from it, without the file names: $dir = 'members/' . $_SESSION['valid_user']; $files1 = scandir($dir); $files2 = scandir($dir, 1); print_r($files1); print_r($files2); result: Array ( [0] => . [1] => .. ) Array ( [0] => .. [1] => . ) Thanks for the help, Jason Link to comment https://forums.phpfreaks.com/topic/90464-looping-through-image-directory/#findComment-463842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.