简体   繁体   中英

PHP Readdir sorting by creation date

Somewhat based on a source I found online, but I want it to sort videos by creation/modification date. I've tried a number of solutions, but can't seem to find or come up with one that I am really satisfied with. I'd greatly appreciate if someone could point me in the right direction.

<?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/>";         
   }
  }
 }
?>

Decided to just drop it and use include this in my project

http://pastebin.com/raw/KXMwWicf

Then I added this to my index

<?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';
?>

Don't know who to credit for original file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM