5

私はワードプレスのブログに取り組んでいます。以前の開発者は、「Exec-PHP」を使用して、ページ内で PHP スクリプトを実行していました。

http://url-of-the-page/「/homez.406/xxx/www/wp-content/xxx/xxx/」に含まれるファイルの一覧に次のように表示されます。

ファイルを日付順に並べたいのですが、やり方がわかりません。誰かがすでにこれを使用していますか?

<!--?php showContent('/homez.406/xxx/www/wp-content/xxx/xxx/','http://url-of-the-page/',false,false); ?-->

これは、functions.php で見つけたものです。

function showContent($path,$webpath,$adminclear,$adminup){

if ($handle = opendir($path))
{
   if ($adminclear==true)

   {
    global $user_ID; if( $user_ID ) :
    if( current_user_can('level_10') ) :
    $auth=true;
    else : 
    $auth=false;
    endif; 
    endif; 
   }

   if ($adminup==true)

   {
    global $user_ID; if( $user_ID ) :
    if( current_user_can('level_10') ) :
    $authup=true;
    else : 
    $authup=false;
    endif; 
    endif; 
   }

   else{$auth=true;$authup=true;}



   if ((isset($_POST['dlfile']))&&($auth==true))
   {
   $removefile=$_POST['dlfile'];
    unlink ($removefile);

   }


   while (false !== ($file = readdir($handle)))
   {
       if ($file != "." && $file != "..")
       {
           $fName  = $file;
           $goodpath=$webpath.$fName;
           $file   = $path.$file;
           $abpath=$path.$fName;


           if(is_file($file)) {
               echo "<p><a href='http://www.otrmd.com/wp-content/themes/FactoryWP/dl.php?p=".$goodpath."&f=".$fName."'>".$fName."</a><br/> Uploaded on ".date ('d-m-Y H:i:s', filemtime($file))."<br/>Size: ".filesize($file)." bytes</p>";

               if($auth==true)
               {
               echo "<form method='post' action=".$_SERVER['REQUEST_URI'].">
               <input type='hidden' name='dlfile' value='".$abpath."'>
               <input type='submit' value='Clear File'>
               </form><br/>";
               }
           } elseif (is_dir($file)) {
               print "<p><a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></p><br/><br/>";
           }
       }
   }

   closedir($handle);
}    
if ($authup==true)
   {

   echo ("[uploadify folder='".$path."' multi=true]");

   }

}
4

1 に答える 1

1

ここでの問題は、関数readdirが使用されていることであり、ドキュメントには次のように書かれています。

The entries are returned in the order in which they are stored by the filesystem.

したがって、ファイルをで並べ替えるには、とscandir組み合わせて使用​​することをお勧めしますuasortfilemtime

交換

while (false !== ($file = readdir($handle)))

$files = scandir($path);
uasort($files, 'sort_by_filemtime');
foreach ($files as $file) {
    ...

そして、スクリプトの最初に次のコールバック関数を宣言します

function sort_by_filemtime($file1, $file2) {
    global $path;
    $file1mtime = filemtime($path.$file1);
    $file2mtime = filemtime($path.$file2);
    if ($file1mtime == $file2mtime) {
        return 0;
    }
    return $file1mtime > $file2mtime ? 1 : -1;
}
于 2012-11-27T15:38:48.417 に答える