den68 Posted February 20, 2011 Share Posted February 20, 2011 Ok back story, this is for a site that will allow people to make recordings of themselves sing. The recorder places files into a local folder but pulls the files in an odd way, I would like the files to be pulled by creation time. I am running on a linux server. This is my code can someone help me figure out how to create an array to pull by creation time rather than the way it is sorting? <?php include("header.php"); include("inc.php"); if (($rec=$_GET['delete'])&&$delete_from) { echo "Deleting $rec ..."; if (file_exists($file = $delete_from . $rec . ".flv")) unlink($file); if (file_exists($file = $delete_from . $rec . ".key")) unlink($file); if (file_exists($file = $delete_from . $rec . ".meta")) unlink($file); if (file_exists($file = "recordings/" . $rec . ".vwr")) unlink($file); } ?> <div class="info"> <b>Video Recordings</b> / <a href="index.php">Record New Video</a><br /> <?php $dir="recordings"; $handle=opendir($dir); while (($file = readdir($handle))!==false) if ((substr($file,-3)=="vwr") && (!is_dir("$dir/".$file))) { $vid=substr($file,0,-4); $params=explode(";;;",implode(file("$dir/".$file))); if (count($params)) { $ts=$params[2]; $tm=floor($ts/60); $ts=$params[2]-$tm*60; $info=$params[0]." ($tm:$ts)"; } echo "<a href='streamplay.php?vid=$vid'><IMG WIDTH='240' TITLE='$info' ALT='$info' BORDER=5 SRC='".(file_exists("snapshots/$vid.jpg")?"snapshots/$vid.jpg":"snapshots/no_video.png")."'></a> "; } ?> </div> Link to comment https://forums.phpfreaks.com/topic/228308-need-help-with-an-array/ Share on other sites More sharing options...
den68 Posted February 21, 2011 Author Share Posted February 21, 2011 Yeah I couldnt figure it out either, seems like it would be simople to sort by created date. Link to comment https://forums.phpfreaks.com/topic/228308-need-help-with-an-array/#findComment-1177847 Share on other sites More sharing options...
kenrbnsn Posted February 21, 2011 Share Posted February 21, 2011 On most Linux systems, you can not get the creation date/time for a file, since it is not stored. You can get the date it was last modified. If you want to do a sort on that time, you can do something like: <?php $files = glob('path/to/files/*'); $tmp = array(); foreach($files as $file) { $tmp[filemtime($file)] = $file; } ksort($tmp); foreach ($tmp as $modtime => $file) { echo $file . ' ---> ' . date('F d Y H:i:s',$modtime) . '<br>'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/228308-need-help-with-an-array/#findComment-1177862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.