Jump to content

filectime function to display latest added image in a folder....pls help


paparanch

Recommended Posts

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!

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);
//..
?>

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.