Parsing the files into an array for downloading
Posted: Wed Aug 27, 2003 9:49 pm
Hi,
I need help for my php script. I have a folder with many jpeg files. Initially, I do it and display them in table for users to click and view. But now, I need them to be display in a drop down menu and when user click on it, they are able to download the file. Can anyone please help me how to do it. Thanks.
My code is as below for your reference.
I need help for my php script. I have a folder with many jpeg files. Initially, I do it and display them in table for users to click and view. But now, I need them to be display in a drop down menu and when user click on it, they are able to download the file. Can anyone please help me how to do it. Thanks.
My code is as below for your reference.
Code: Select all
<?php
function getFiles($dir)
{
$filedir = getcwd();
$filename = getHeader($filedir);
print "<table border=1 align=center cellpadding=4 width=725>";
print "<tr>
<th align=left bgcolor="yellow" width=500><font size=-1 face="Times New Roman"><b>Name:</b></font></th>
<th align=left bgcolor="yellow" width=125><font size=-1 face="Times New Roman"><b>Size:</b></font></th>
<th align=left bgcolor="yellow" width=100><font size=-1 FACE="Times New Roman"><b>Updated:</b></font></th>
</tr>";
if (is_dir($dir)) // check if it's a valid directory
{
$dir = @opendir($dir); // open dir
if($dir) // if it IS a dir
{
while (($file = @readdir($dir)) == true) // read from the dir get filenames
{
if ($file != "." && $file != ".." && $file != ".DS_Store" && $file !="drop box") //don't display certain filenames
{
$file_array[]=$file; //put into array
}
}
}
sort($file_array);
reset($file_array);
// printing
for($i=0;$i<count($file_array);$i++) // loop the array
{
$nfile = $file_array[$i]; // get each row
// make sure it's not an include file or index file
if (!strstr($nfile,".inc.php") && !strstr($nfile,"index.php") && !strstr($nfile, ".php"))
{
$fsize=round(filesize($nfile)/1000)*1; //get filesize
$datemod = date("m/d/y", filemtime($nfile)); // get filedate
if (is_dir($nfile)) // the file is a directory
{
}
else // the file is not a directory
{
print "<tr><td bgcolor="#CCCCCC"><font size=-1 FACE="Times New Roman"><a href="$nfile">$nfile</a></font></td>";
print "<td align=left bgcolor="#CCCCCC"><font size=-1 FACE="Times New Roman" color="#000000">$fsize KB</font></td>";
print "<td align=left bgcolor="#CCCCCC"><font size=-1 FACE="Times New Roman" color="#000000">$datemod</font></td></tr>\n";
}
}
}
print "</table>";
}
else
{ print "not a valid directory"; }
}
?>
Regards.
Fernado
?>