Displaying files from folder into the browser
Posted: Mon Aug 25, 2003 10:20 pm
Hi,
I am new in PHP and i really need help from you. I am trying to retrieve the lastest file from the particular folder and display it into the browser while the rest of the files remain as downloading links for the users. Can anyone please help me with my problems. Thanks.
Regards.
Fernado
I am new in PHP and i really need help from you. I am trying to retrieve the lastest file from the particular folder and display it into the browser while the rest of the files remain as downloading links for the users. Can anyone please help me with my problems. Thanks.
Regards.
Fernado
Code: Select all
<?php
include("doc_function.inc.php");
htmlheader(); // prints html header
$dir = "./"; // current directory
// Print the directory name as a heading title
$filedir = getcwd(); // get current dir
$dirname = getHeader($filedir);
print "<br>";
print "<font size=+1 face="Times New Roman" color="Blue"><b> ";
print "$dirname </b>";
print "</font> ";
print "<hr>";
getFiles($dir); // displays all the files in the folder
getFooter($dir); // displays the "back" and "home" links
print "</blockquote>
<body>
</html>";
$number_of_records = 0;
$directory = "./";
$directory_listing = array();
recrusive_list_dir_contents($directory);
krsort($directory_listing);
reset($directory_listing);
$i = 0;
while(list($ctime, $file) = each($directory_listing))
{
if($i++ == $number_of_records)
break;
else
$recent_files[$ctime] = $file;
}
Global $recent;
$recent=$file;
echo "Latest file path is $recent";
function recrusive_list_dir_contents($directory)
{
GLOBAL $directory_listing;
if(!is_dir($directory)){
echo "$directory is not a directory";die;
}
if($directory[strlen($directory)-1] != "/")
$directory .= "/";
$dp = opendir($directory);
while (($file = readdir($dp)) !== false){
if($file[0] != "." && $file != "index.php")
{
if(is_dir($directory.$file))
recrusive_list_dir_contents($directory.$file);
else
$directory_listing[filectime($directory.$file)] .= $directory.$file;
}
}
//return 0; // a mere formality
}
$openfile=fopen ($recent ,'r+b' );
?>
?>