PHP Help: Retrieving File Names from folder

1 replies
I am currently editing a script and I need it to go into /images/ and then return the filenames of the five images that are located there.

I need the filenames to be named within the script as image1, image2, image3, image4 and image5.

While the general order will not matter, I do need some way of choosing which image will be set as image1. I could name the file 1imagename.jpg and then remove the 1 later.

I am by no means a PHP expert but I'm pretty resourceful and if anyone can throw me a bone I should be able to knock something together myself.
#file #folder #names #php #retrieving
  • Profile picture of the author WilliamBlah
    My botch job has got me this far. I am now able to output the names of the files:

    PHP Code:

    opendir(dirname(__FILE__) . '/images'); # Open the path
    while ( = readdir()) { 
    if (
    preg_match("/.jpg/",)) { # Look at only files with a .jpg extension
    .= "|";
    if ( > 
    0) {
    explode('|', );
    ", , , , ";

    EDIT: Managed to work it all out now!
    {{ DiscussionBoard.errors[5168246].message }}

Trending Topics