View Single Post
ישן 10-07-09, 16:18   # 8
AlmogBaku
חבר וותיק
 
AlmogBaku's Avatar
 
מיני פרופיל
תאריך הצטרפות: Nov 2007
מיקום: מודיעין
הודעות: 1,022

AlmogBaku לא מחובר  

בשבילך-

PHP קוד:
<?php
/**
 * Getting Files By Modified time
 * 
 * @author Almog Baku
 * @link http://www.AlmogBaku.com
 *
 * @param string $dir         - Default: current direction
 * @return array() $files
 */
function get_files_byDate($dir="./") {
    
$list    get_file_list($dir);
    
usort($list' _byDate_sorter');
    
    
$return = array();
    foreach (
$list as $value)
        
$return[] = $value['file'];
    
    return 
$return;
}
/**
 * Getting file list
 *
 * @param string $dir
 * @return array $list[]['time']['file']
 */
function _byDate_get_file_list($dir="./") {
    
$list    = array();
    
    if (
$handle opendir($dir)) {
        while ((
$file readdir($handle)) !== false) {
            if((
$file != ".") && ($file != "..")) {
                
$list[]    = array('time'=>filemtime($dir $file), 'file'=>$dir $file);
            }
        }
        
closedir($handle);
    }
    return 
$list;
}

/**
 * Sorter by `time` index of file list
 *
 * @param current $a
 * @param next $b
 * @return return before(-1) or after(+1)
 */
function _byDate_sorter($a$b) {
    if(
$a['time']<$b['time'])
        return -
1;
    else
        return 
1;
}

/**
 * @example 
 */
print_r(get_files_byDate());
?>
  Reply With Quote