Jump to content

Displaying images in order of their name?


memzenator

Recommended Posts

Hello. :) I am using this code to display the images in a directory ("portraits")

 

<?php
$path = "./portraits";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if(ereg("(.*)\.(jpg|JPG|bmp|jpeg|png|gif)", $file)){
echo "<img src='portraits/$file' height='100%'> ";
}
}
closedir($dir_handle);

?>

 

and I'd like to have them displayed in order of their name. They are named "01", "02", and so on.

I think this should be pretty simple.. I don't know much about php, so any help would be great. Thanks.

might try here http://www.nstoia.com/toh/listdir.php

 

#    The script reads through a given folder

#    and displays the files contained therein

#

#    There are five variables you may alter

#

#    1.    $allowed_ext - this array is used to set which

#        type of file will be listed

#

#    2.    $directory - this is used to set which directory

#        will be searched/listed

#

#    3.    $do_link - TRUE means display the file

#        name as a link to the file; FALSE means

#        do NOT make the name a link

#

#    4.    $sort_what - this determines what the

#        data will be sorted upon: 0 is by name;

#        1 is by size; 2 is by date last modified

#

#    5.    $sort_how - describes how to sort; 

#        0 means to sort ASCENDING 

#        (oldest to newest, smallest to largest, Z to A); 

#        while 1 means to sort DESCENDING

 

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.