Regoch2 Posted September 14, 2012 Share Posted September 14, 2012 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! Thanks! <?php /* Configuration Start */ $orig_directory = 'images/galeria'; /* Configuration end */ $allowed_types=array('jpg','jpeg','gif','png'); $file_parts=array(); $ext=''; $title=''; $i=0; /* 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!"); $i=1; 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: */ if(in_array($ext,$allowed_types)) { /* Outputting each image: */ echo '<img src="/'.$orig_directory.'/'.$file.'" width="893" height="597" /> '; } } /* Closing the directory */ closedir($dir_handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/ Share on other sites More sharing options...
spiderwell Posted September 14, 2012 Share Posted September 14, 2012 php 5 has scandir, which will do this for you. check it out here Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/#findComment-1377821 Share on other sites More sharing options...
Regoch2 Posted September 14, 2012 Author Share Posted September 14, 2012 Gonna check it, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/#findComment-1377830 Share on other sites More sharing options...
hakimserwa Posted September 14, 2012 Share Posted September 14, 2012 i think you question how to arrange by name is it? Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/#findComment-1377832 Share on other sites More sharing options...
Regoch2 Posted September 14, 2012 Author Share Posted September 14, 2012 This is what I get working! Thanks spiderwell for direction! <?php $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.'" /> '; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/#findComment-1377858 Share on other sites More sharing options...
spiderwell Posted September 14, 2012 Share Posted September 14, 2012 happy to help. Quote Link to comment https://forums.phpfreaks.com/topic/268356-align-by-name/#findComment-1377860 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.