tagger Posted August 11, 2007 Share Posted August 11, 2007 Hi, I'm new to php and hope to find some help here. I searched for this but couldn't find anything. I know HTML and CSS very well. I'm a lazy guy who has to upload a fair amount of pictures and show them online. To make the story short: I'm an artist who tries to upload every sketchbook page to show others. Basically I would like to have 1 directory where I could upload images (jpg format) and the script searches through that directory and displays all the images with <img> tags. I would like to have the index.php in the root directory and the images in a folder called 'images'. I would be very glad if somebody could code something for me and gve a small explanation. I made a script which didn't 'really' worked out because it did display the images but also other weird stuff that I don't understand. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/ Share on other sites More sharing options...
AndyB Posted August 11, 2007 Share Posted August 11, 2007 As simple as it gets - glob() is explained in the manual. Add this to your main folder (as index.php if you want). <?php foreach (glob("images/*.jpg") as $filename) { echo "<img src='" . $filename . "'><br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/#findComment-321202 Share on other sites More sharing options...
tagger Posted August 11, 2007 Author Share Posted August 11, 2007 Works perfectly, thanks a lot! I have an additional question, it would be great if you could answer this too: When I want to apply a style or use a class tag with the image can I just do it like this: <?php foreach (glob("images/*.jpg") as $filename) { echo "<img class="sketchbookimages" src='" . $filename . "'><br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/#findComment-321214 Share on other sites More sharing options...
calabiyau Posted August 11, 2007 Share Posted August 11, 2007 Like below: <?php foreach (glob("images/*.jpg") as $filename) { echo '<img class="sketchbookimages" src="' . $filename . '"><br/>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/#findComment-321219 Share on other sites More sharing options...
LiamProductions Posted August 11, 2007 Share Posted August 11, 2007 Even though this isnt my topic.. Thanks. I've learnt a new syntax Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/#findComment-321222 Share on other sites More sharing options...
LiamProductions Posted August 11, 2007 Share Posted August 11, 2007 Thanks to this i made a script (I dont achually need it but i still made it i still had problems lol but i fixed them) <?php error_reporting(E_ALL); foreach(glob("*.php") as $filename){ echo "<a href=\"$filename\">$filename</a> <br />"; } ?> it will get all the file names with .php and link to the file name like a directory kinda Quote Link to comment https://forums.phpfreaks.com/topic/64425-solved-display-all-images-from-a-directory/#findComment-321229 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.