Jump to content

Align by name


Recommended Posts

I find this script online for geting images from directory. Is there any way to change code to get it align by name? With this code I get random align!


/* Configuration Start */
$orig_directory = 'images/galeria';
/* Configuration end */


/* Opening the image directory and looping through all the thumbs: */
$dir_handle = @opendir($orig_directory) or die("There is an error with your image directory!");
while ($file = readdir($dir_handle)) 
/* Skipping the system files: */
if($file=='.' || $file == '..') continue;
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));

/* Using the file name (withouth the extension) as a image title: */
$title = implode('.',$file_parts);
$title = htmlspecialchars($title);

/* If the file extension is allowed: */	
	/* Outputting each image: */
	echo '<img src="/'.$orig_directory.'/'.$file.'" width="893" height="597" /> ';

/* Closing the directory */

Link to comment
Share on other sites

This is what I get working! Thanks spiderwell for direction!

$folder = 'images/galeria'; // Choose directory
$extensions = array('jpg','jpeg','gif','png');
$slika = scandir($folder);
sort($slika); // Sort the array
foreach($slika as $key => $value) {       
	$get_extensions = explode(".",$value);
        $ext = $get_extensions[count($get_extensions) - 1];
         // Only include files with desired extensions
        if (in_array($ext, $extensions))
    $title = substr($value, 0,strrpos($value,'.')); // Get filename for alt
	echo '<img src="/'.$folder.'/'.$value.'" width="893" height="597" alt="'.$title.'" /> '; 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.