note 60404 deleted from function.opendir by mazzanet
| From: | mazzanet@php.net | Date: | Fri, 06 Jan 2006 09:48:14 +0000 |
| Subject: | note 60404 deleted from function.opendir by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101292@lists.php.net to get a copy of this message | ||
Note Submitter: asharm4 at ilstu dot edu
----
//A function to display the contents of the directory ordered by date modified....
<table width="100%" border="0" class="copysm" align=center>
<tr>
<td>
<h3>Downloads</h3>
</td>
</tr>
<tr><td align="justify">
A List of all the files in the directory mentioned
</td></tr>
<tr>
<td>
<?
$content_array = array();
//call function list_dir and pass it ..here I am using relative path..Absolute path can be also
used..
$content_array=list_download();//function is given in the later part of this code
$num_content;
$num_content = count($content_array);
$display_num = $num_content ;
//for sorting the files according to the time of creation ...
foreach($content_array as $res)
$sortAux[] = $res[1];
array_multisort($sortAux, SORT_DESC, $content_array);
for ($i=0; $i<=$display_num; $i++)
{
if (strrchr($content_array[$num_content - $i][0],"."))
{
$display_name = ereg_replace ( ".xls", "",
$content_array[$num_content - $i][0]);
$display_name = ereg_replace ( "_", " ",
$display_name);
$display_name = ucwords($display_name);
print "<img src='images/excel_file.gif'
width='28' height='28'> <a
href='reports/".$content_array[$num_content - $i][0]."'
class='headlinks3'>".$display_name."</a><br><br>";
}
}//End for
?>
</td>
</tr>
</table>
//this function would read and return the contents of the directory
function list_download()
{
$retVal = array();
//set current working directory
$dirname = getcwd();
$dirname = $dirname."/download";
//Load Directory Into Array
$handle=opendir($dirname);
$i=0;
while ($file = readdir($handle))
if ($file != "." && $file != "..")
{
$retVal[$i][0] = $file;
$retVal[$i][1] = date ("Y m d D M j G:i:s",
filemtime($dirname."/".$file));
$i++;
}
//Clean up and sort
closedir($handle);
return $retVal;
} //--End list_downloads function