Jump to content

[SOLVED] Display all images from a directory?


tagger

Recommended Posts

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!

Works perfectly, thanks a lot! :D

 

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/>";
}
?>

 

 

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.