paparanch Posted March 2, 2009 Share Posted March 2, 2009 hi gurus! i am back for another question regarding filectime function... here's what i got so far...this code displays images from a folder with pagination(by mr.russel) now, what i wanted is to display the latest added image at the top or the first image among the four images to be displayed. <?php $page = $_GET['page']; $rpp = 2; if($page==""){ $page = 1; } $dirArr = scandir('comments/Birthday/'); function rem_invalid($arr) { foreach ($arr as $k => $v) { if (stristr($v,'.gif') === false) unset($arr[$k]); } } $dirArr = preg_grep("/^.*\.gif$/i",$dirArr); if ($c = count($dirArr)) { $dirArr = array_combine(range(0,count($dirArr) - 1),$dirArr); $numOfPages = ceil($c / $rpp); for ($i = (($page - 1) * $rpp); $i < min($c,($page * $rpp)); $i++) { $filenames = $dirArr[$i]; //$filename = filectime($path/$filenames); <<< this is wrong...what is right way for this? echo "<img src='comments/Birthday/$filenames' width='200'><br>"; echo "<input type='text' value='$filename'><br><br>"; } } echo "<br /><br />"; for ($i = 1; $i <= $numOfPages; $i++) { echo "<a href='view_pix.php?page=$i'>"; echo " ".$i." "; echo "</a>"; } ?> tnx in advanced! Link to comment https://forums.phpfreaks.com/topic/147538-filectime-function-to-display-latest-added-image-in-a-folderpls-help/ Share on other sites More sharing options...
MadTechie Posted March 2, 2009 Share Posted March 2, 2009 Try this <?php $dirArr = array_combine(range(0,count($dirArr) - 1),$dirArr); $dirArr2 = array(); foreach($dirArr as $file) { $key = $filemtime($file); $dirArr2[$key] = $file; } krsort($dirArr2); $dirArr = array_values($dirArr2) unset(dirArr2); $numOfPages = ceil($c / $rpp); //.. ?> Link to comment https://forums.phpfreaks.com/topic/147538-filectime-function-to-display-latest-added-image-in-a-folderpls-help/#findComment-774567 Share on other sites More sharing options...
paparanch Posted March 3, 2009 Author Share Posted March 3, 2009 ahhmmm...tnx for this...but where am i going to insert this code or should i replace something? Link to comment https://forums.phpfreaks.com/topic/147538-filectime-function-to-display-latest-added-image-in-a-folderpls-help/#findComment-775163 Share on other sites More sharing options...
MadTechie Posted March 4, 2009 Share Posted March 4, 2009 replace your posted code with <?php $page = $_GET['page']; $rpp = 2; if($page==""){ $page = 1; } $dirArr = scandir('comments/Birthday/'); function rem_invalid($arr) { foreach ($arr as $k => $v) { if (stristr($v,'.gif') === false) unset($arr[$k]); } } $dirArr = preg_grep("/^.*\.gif$/i",$dirArr); if ($c = count($dirArr)) { $dirArr = array_combine(range(0,count($dirArr) - 1),$dirArr); //above is your code $dirArr2 = array(); foreach($dirArr as $file) { $key = $filemtime($file); $dirArr2[$key] = $file; } krsort($dirArr2); $dirArr = array_values($dirArr2) unset(dirArr2); //below is your code $numOfPages = ceil($c / $rpp); for ($i = (($page - 1) * $rpp); $i < min($c,($page * $rpp)); $i++) { $filenames = $dirArr[$i]; //$filename = filectime($path/$filenames); <<< this is wrong...what is right way for this? echo "<img src='comments/Birthday/$filenames' width='200'><br>"; echo "<input type='text' value='$filename'><br><br>"; } } echo "<br /><br />"; for ($i = 1; $i <= $numOfPages; $i++) { echo "<a href='view_pix.php?page=$i'>"; echo " ".$i." "; echo "</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/147538-filectime-function-to-display-latest-added-image-in-a-folderpls-help/#findComment-775907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.