2016-05-26 6 views
0
 <?php 
     //basic directory 
     $dir = 'dir'; 
     //hardcoded hours and minutes for specific time 
     $hours = 11 ; 
     $minutes = 2 ; 

     date_default_timezone_set('Asia/Kolkata'); 
     $today = date('F d, Y'); 

      if (is_dir($dir)) { if ($dh = opendir($dir)) { 

        while (($file = readdir($dh)) !== false) {     
         clearstatcache(); 

         if(is_file($dir."/".$file)) { 
//$filename will store the last modified files which in folder     
           $filename = filemtime($dir."/".$file); 
      //condition for some relevent time 
           if(date('F d, Y',$filename) == $today && date("H", $filename) >= $hours && date("i", $filename) >= $minutes) 
           { 
    // here i want the sorting code. because it doesnt display the time wise file in output 
           echo $file; 
           echo " - ";      
           echo "Last modified: " . date("F d, Y H:i:s.", $filename); 
           echo "<br>"; 
           } 
         } 
         }    
         echo "<br>"; 
         closedir($dh); 
        } 
       } 

      ?> 
     /* 
     i have this output. but it is not perfect i want the last modified come first 
     through sorting . 

     test2.php - Last modified: May 26, 2016 11:30:10. 
     test3.php - Last modified: May 26, 2016 11:32:07. 
     test.txt - Last modified: May 26, 2016 13:13:11. 
     */ 
+1

'$ filename = filemtime' - あなたの変数名に、内容に完全には関係しない名前を付けることができると思いますか? ;) –

答えて

0

あなたはすでにすべての詳細(Unixタイムスタンプとパス)を持っています。

bool ksort (array &$array [, int $sort_flags = SORT_REGULAR ]) 

:一緒に作品を置くために、あなたの好みに合わせてksortで並べ替え、値(あなたはユニークなタイムスタンプごとに複数のファイルを持つことができます覚えている)として、キーとパスとしてタイムスタンプを使用してアレイを作成することができますデータを相関関係に維持しながら、キーで配列をソートします。これは主に連想配列に役立つ です。

これは、ディレクトリからファイルを取得するときにファイルを表示できなくなったため、後で処理するためにファイルを保存して後で表示する必要があることを意味します。

関連する問題