[英]PHP Readdir sorting by creation date
有些基於我在網上找到的來源,但我希望它按創建/修改日期對視頻進行排序。 我已經嘗試了很多解決方案,但似乎無法找到或想出一個我真正滿意的解決方案。 如果有人能指出我正確的方向,我將不勝感激。
<?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/>";
}
}
}
?>
決定放棄它並在我的項目中使用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';
?>
不知道誰歸功於原始文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.