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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.