Jump to content

How do it make this so it only gets the latest file in the list not all files


ztealmax

Recommended Posts

How do it make this so it only gets the latest file (Last modified file) in the list not all files

[code]<?php
$this = $PHP_SELF;
$dir  = $DOCUMENT_ROOT."news/";

$files = opendir($dir);
$file_list = array();
$file_sort = array();

if(empty($sort))$sort="date";
if(empty($r)) $r=1;

$cnt = 1;

    while ($file = readdir($files))
{
$full_path = $dir."/".$file;
if(!is_dir($full_path))
{
$ext = explode(".",$file);
$i=count($ext);
if($i>1)$file_details["ext"] = strtolower($ext[$i-1]);
$file_details["name"] = $ext[0];
$file_details["date"] = filectime($full_path);
$file_list[$cnt] = $file_details;

$key = strtolower($file_details[$sort]);
$file_sort[$cnt] = $key;

$cnt++;
}
}

if($r)arsort($file_sort);
else asort($file_sort);


?>

<?PHP require_once("theme.php");?>
<table width="465" border="0" cellpadding="3" cellspacing="0" class="smallblacktext">
  <tr>
    <td width="174"><?php print($this);?><?php print(!$r);?>Name</td>
    <td width="141"><?php print($this);?><?php print(!$r);?>Date</td>
  </tr>
  <tr bgcolor="#0033CC">
    <td height="3" colspan="5"> </td>
  </tr>
<?php
while(list($key, $value)=each($file_sort))
{
$value = $file_list[$key];
?>
  <tr>
    <td width="174"><a href="read.php?text=news/<?php print($value["name"]);?>" target="content"><?php print($value["name"]);?></a></td>
    <td width="141"><?php print(date("Y/m/d H:i",$value["date"]));?></td>
  </tr>

<?php


}
?>



</table>[/code]
Basicly what i  want the script to do is to only open latest file for read.
Thanx all for you help :)

//Martin
[quote author=artacus link=topic=118949.msg486542#msg486542 date=1166343953]
Sure, after you try to do a couple examples yourself.
[/quote]

well i did, didnt work did it , thats why i ask here.....

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.