PHP Readdir按创建日期排序

时间:2016-10-30 22:08:14

标签: php sorting scandir opendir

有些基于我在网上找到的来源,但我希望它按创建/修改日期对视频进行排序。我已经尝试了很多解决方案,但似乎无法找到或想出一个我真正满意的解决方案。如果有人能指出我正确的方向,我将非常感激。

<?php
$dir = isset($_GET['cat']) ? $_GET['cat'] : 'straight';
$limit = 30; 
$page = (int)$_GET['page']?:0;
$skip = $limit * $page;
if ($handle = opendir($dir)) {
    $blacklist = array('.htaccess', '..', 'index.html');
    $skiped = 0;
    while (false !== ($file = readdir($handle))) {
    if (!in_array($file, $blacklist)) { 
    $skipped++;
    if ($skipped < $skip || $skipped >= $skip + $limit) {
        continue;
}

echo "<div class=\"video-title\">
<a href=\"\">". $file ."</a>
</div>

<div style='display: block'>
<video loop controls
preload=\"auto\"
width=\"800px\" 
id=\"video\" 
class=\"b-lazy vjs-big-play-centered vjs-sublime-skin video-js\" 
data-setup=\"{}\" >

<source src=\"". $dir . "/" . $file ."\" type=\"video/webm\">
<p class=\"vjs-no-js\">
To view this video please enable JavaScript, and consider upgrading to a web browser that
<a href=\"http://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 webm video</a>
</p>
</video>
</div>
<div class=\"video-footer\">
<a class=\"float-left\" href=\"". $dir . "/" . $file ."\">Download</a>
<a class=\"float-left\" href=\"". $dir . "/" . $file ."\">Share</a>
<a class=\"float-right\" href=\"contact.php?title=report&file=" . $file ."\">Report</a>
<a class=\"float-right\" href=\"Thread-" . $file ."\>Comment</a>
</div>

<br/>";         
   }
  }
 }
?>

1 个答案:

答案 0 :(得分:0)

决定放弃它并在我的项目中使用include

http://pastebin.com/raw/KXMwWicf

然后我将其添加到我的索引

<?php
$dir = isset($_GET['cat']) ? $_GET['cat'] : 'straight';
define('NUMBER_PER_PAGE', 30); 
define('PATH_TO_DIR', $dir); 
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; 
$list = new PaginateDirectory(PATH_TO_DIR, $page); 
?> 

<td><?php echo $list->displayCount(); ?></td> 
<div class="pagination"><?php echo $list->displayLinks(); ?></div>
<?php foreach( $list->getImages() as $index => $image ){ ?> 
<?php 
$file = basename($image['file']);
print 'whatever'.$file.'whatever';
?>

不知道归档原始文件的人。