php sort by folder created date


#1

Hi Experts,
Currently this file display all folder order by name but i want to order by folder created date.

index.php contains :
[php]

<?php foreach($categories_array as $photo_category=>$photos_array){?> 
 
    <?php  
    $category_thumbnail = $gallery_url."/layout/pixel.gif"; 
    if(file_exists('files/'.$photo_category.'/thumbnail.jpg')){ 
        $category_thumbnail = $gallery_url.'/'.$photo_category.'/thumbnail.jpg'; 
    } 
     
    $category_url = $gallery_url.'/'.$photo_category; 
    ?> 
     
      <span class="category_thumbnail_span" style="width:<?php echo $settings_thumbnail_width;?>px; height:<?php echo $settings_thumbnail_height+20;?>px;"> 
    <a class="category_thumbnail_image" href="<?php echo $category_url;?>" style="width:<?php echo $settings_thumbnail_width;?>px; height:<?php echo $settings_thumbnail_height;?>px; background-image:url('<?php echo $gallery_url;?>/layout/lens_48x48.png');" title="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>"> 
    <img src="<?php echo $category_thumbnail;?>" width="<?php echo $settings_thumbnail_width;?>" height="<?php echo $settings_thumbnail_height;?>" alt="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>" /> 
    </a> 
    <a class="category_thumbnail_title" href="<?php echo $category_url;?>" title="<?php echo htmlentities(ucwords(str_replace('-', ' ', $photo_category)));?>"> 
    <?php echo htmlentities(str_replace('-',' ', truncate_by_letters($photo_category, 16, '..')), ENT_QUOTES, "UTF-8");?> (<?php echo count($photos_array);?>) 
    </a> 
    </span> 
 

<?php } ?> 
[/php]

include file contains:
[php]
$categories_array = array();

$timer_1 = microtime(true);
// loop over files directory and read the categories
if ($handle = opendir(‘files’)) {
while (false !== ($folder = readdir($handle))) {
if(is_dir(‘files/’.$folder) and $folder!=’.’ and $folder!=’…’){

        // define this key in the array, it will be blank, store categories as keys 
        $categories_array[$folder] = array(); 

        // $total_photos_array[$folder] = 0; 
         
        $files_in_dir = scandir('files/'.$folder); 
        foreach($files_in_dir as $file){ 
            // if file ends in _thumb.jpg 
            if(strpos($file, '_thumb.jpg') === strlen($file)-10){ 
                // $total_photos_array[$folder]++; 
                $base_file_name = substr($file, 0,  strlen($file)-10); 
                // insert this file in the array of files 
                array_push($categories_array[$folder], $base_file_name); 
            } 
        } 
         
    } 
} 
closedir($handle); 

}
$timer_2 = microtime(true);

ksort($categories_array);

[/php]


#2

Without being able to run the code i am unable to test however, try changing this:
[php]$base_file_name = substr($file, 0, strlen($file)-10);[/php]

to this
[php]$base_file_name = filemtime($file);[/php]

Give it a whirl an let me know how you get on.
Red :wink:


#3

hi thanks for reply.
tried but no luck. still same.


#4

here is the complete include file
[php]

<?php include("settings.php"); $page_load_start = microtime(true); if (!isset($_SESSION)) { session_start(); } // this is needed to properly handle the special characters in file names, image resize might fail without this setlocale(LC_CTYPE, "en_US.UTF-8"); $gallery_domain = str_replace("www.", "", $_SERVER['HTTP_HOST']); // the gallery_url is the url of the gallery script (the folder), relative to site root, e.g /gallery $gallery_url = dirname($_SERVER['SCRIPT_NAME']); $gallery_url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $gallery_url); error_reporting(E_ALL ^ E_NOTICE); include("system_functions.php"); // test if this user is admin or not $is_admin = false; if($_SESSION['session_admin'] == md5($_SESSION['session_secret'].$settings_secret)){ $is_admin = true; } // $photo_categories_array = array(); // $total_photos_array = array(); // this will be an array in array, first key is cat, second key is image file: // $categories_array['cars']['retro-car'] $categories_array = array(); $timer_1 = microtime(true); /* // loop over files directory and read the categories if ($handle = opendir('files')) { while (false !== ($folder = readdir($handle))) { if(is_dir('files/'.$folder) and $folder!='.' and $folder!='..'){ // define this key in the array, it will be blank, store categories as keys $categories_array[$folder] = array(); // $total_photos_array[$folder] = 0; $files_in_dir = scandir('files/'.$folder); foreach($files_in_dir as $file){ // if file ends in _thumb.jpg if(strpos($file, '_thumb.jpg') === strlen($file)-10){ // $total_photos_array[$folder]++; $base_file_name = substr($file, 0, strlen($file)-10); $base_file_name = filemtime($file); // insert this file in the array of files array_push($categories_array[$folder], $base_file_name); } } } } closedir($handle); } */ // loop over files directory and read the categories $scandir_array = scandir('files'); foreach($scandir_array as $folder){ if(is_dir('files/'.$folder) and $folder!='.' and $folder!='..'){ // define this key in the array, it will be blank, store categories as keys $categories_array[$folder] = array(); // $total_photos_array[$folder] = 0; $files_in_dir = scandir('files/'.$folder); foreach($files_in_dir as $file){ if($file!='.' and $file!='..'){ // if file is not the category thumbnail (thumbnail.jpg) and not _thumb.jpg and not _small.jpg if($file != "thumbnail.jpg" and substr($file, strlen($file)-10) != "_small.jpg" and substr($file, strlen($file)-10) != "_thumb.jpg"){ // $total_photos_array[$folder]++; //$base_file_name = substr($file, 0, strlen($file)-4); $base_file_name = filemtime($file); // insert this file in the array of files array_push($categories_array[$folder], $base_file_name); //echo "
$base_file_name"; } } } } } $timer_2 = microtime(true); // !! if you use wrong sorting parameter it will convert the category string keys into integer ksort($categories_array); //usort($categories_array); // test if imagemagick is installed $imagemagick_installed = false; @exec("convert -version", $convert_output_array); if(strpos($convert_output_array[0], "imagemagick")){ $imagemagick_installed = true; } ?>

[/php]


#5

hi guys. any update ?


#6

Thought i posted an update here yesterday, my bad! :-[

I was unable to run the script as the are other includes that fail.

Red :wink:


#7

here is the files


free-php-gallery.zip (107 KB)