note 60404 added to function.opendir
| From: | asharm4 at ilstu dot edu | Date: | Thu, 05 Jan 2006 23:29:37 +0000 |
| Subject: | note 60404 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101277@lists.php.net to get a copy of this message | ||
//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
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60404
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60404&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60404&report=yes
Search -- http://master.php.net/manage/user-notes.php