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.
        */
4

1 に答える 1

0

すべての詳細 (Unix タイムスタンプとパス) は既にあります。ピースをまとめるには、タイムスタンプをキーとしてパスを値として使用して配列を作成し (一意のタイムスタンプごとに複数のファイルを持つことができることに注意してください)、ksortを使用して好みに合わせて並べ替えます。

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

キーとデータの相関関係を維持しながら、配列をキーでソートします。これは、主に連想配列で役立ちます。

これは、マイナーではあるが肯定的な再設計を意味します。ディレクトリからファイルを取得するときにファイルを表示することはできなくなりました。さらに処理するためにファイルを保存し、後ですべて表示する必要があります。

于 2016-05-26T12:14:02.720 に答える