gdfhghjdfghgfhf Posted April 15, 2008 Share Posted April 15, 2008 i have a bunch of pics in a folder of my site (called /images/), and on a page i'd like to display all pictures starting with the prefix "photo_" the files i want are all starting by photo_ but have different names, and there is too many to enter them manually how would it be possible to find all pics with that particuliar prefix, and display them? Link to comment https://forums.phpfreaks.com/topic/101170-find-all-images-in-a-folder-starting-by-photo_-and-display-them/ Share on other sites More sharing options...
Orio Posted April 15, 2008 Share Posted April 15, 2008 glob() is your friend <?php //Get all of the pictures that start with "photo_" $pics = glob("images/photo_*"); //Display them foreach($pics as $pic) echo '<image src="images/'.$pic.'"><br>\n'; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/101170-find-all-images-in-a-folder-starting-by-photo_-and-display-them/#findComment-517488 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 15, 2008 Author Share Posted April 15, 2008 Thanks a lot! Did exactly what i wanted only one detail: the first image i am getting is blank, it is trying to show image from "images/photo_" nothing more... there isnt even a filename after the prefix.... i have 8 images in the folder i am testing, and it is displaying 9... so its not a problem with the files or the filenames weird Link to comment https://forums.phpfreaks.com/topic/101170-find-all-images-in-a-folder-starting-by-photo_-and-display-them/#findComment-517493 Share on other sites More sharing options...
discomatt Posted April 15, 2008 Share Posted April 15, 2008 Just to make sure foreach($pics as $pic) if ( file_exists('images/'.$pic) ) echo '<image src="images/'.$pic.'"><br>\n'; Seems redundant though. Try dumping $pics with print_r... might help you get to the bottom of the invalid file issue. Link to comment https://forums.phpfreaks.com/topic/101170-find-all-images-in-a-folder-starting-by-photo_-and-display-them/#findComment-517505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.