Jump to content

displaying files


Nandini

Recommended Posts

Hi

I am displaying files from on directory. Everything working. But i want to display latest added records as first record (Last come first in order). Here is my script .

 

<?php

$path="/usr/local/netz/var/spool/netz/fax/";

if($path)

{

if(`ls -A $path`)

{

$i=1;

$TrackDir=opendir($path);

while ($file = readdir($TrackDir)) {

if ($file == "." || $file == "..") {

}

elseif(preg_match('/\b.pdf\b/', $file)) {

echo "<tr bgcolor='#acbdee'>";

echo "<td class='data' width='10%'>$i</td>";

echo "<td class='data' width='30%'>".$file."</td>";

echo '<td class="data" width="30%" align="center"><table border="0" width="50%"><tr><td align="right"><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href="fax_download.php?download_file='.$file.'" class="fax_links" title="Download"><img src="../images/download.gif" border="0"></a></font></td><td align="right"><a href="delete_fax.php?file='.$file.'" class="fax_links" title="Delete"><img src="../images/delete.gif" border="0"></a></td></tr></table></td>';

echo "<tr>";

$i++;

}

}

closedir($TrackDir);

}

else {

echo "<br><center><b>No records found</b></center>";

}

}

?>

 

Can anyone help me

Link to comment
https://forums.phpfreaks.com/topic/128809-displaying-files/
Share on other sites

why do you need to call the shell's ls command?

anyway, here's another way

$path = realpath('/path/test');
$objects = new DirectoryIterator($path);
foreach($objects as $name => $object){
     if ( $objects->isFile($name) && substr($object,-4,4 )==".txt" ) {
       $records[$object->getMTime()]=$object->getFileName();;
     }
}
ksort($records);
print_r($records);

Link to comment
https://forums.phpfreaks.com/topic/128809-displaying-files/#findComment-667814
Share on other sites

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.