function Downloads($dir = '.') { //open current dir for reading.. $handle = @opendir($dir); //start the table where files are going to be listed.. echo '<table border="1" width="50%" style="border-collapse: collapse;" bordercolor="#000000" align="center"> <tr> <td width="40%" align="center"><b>File Name</b></td> <td width="30%" align="center"><b>File Size</b></td> <td width="30%" align="center"><b>Last Modified</b></td> </tr>'; //now loop through files.. while (false !== ($file = readdir($handle))) { //exclude the dots.. if ($file !== '.' && $file !== '..') { //get file stats $info = stat($file); $stat1 = round($info['size'] / 1024, 2); $stat2 = date('j-n-Y H:i:s', $info['mtime']); echo '<tr> <td width="40%">'; echo "<a href=\"$file\">$file</a></td>\n\t"; echo ' <td width="30%" align="center">'.$stat1.' KB</td> <td width="30%" align="center">'.$stat2.'</td> </tr>'; } } echo '</table>'; //clear the cache.. clearstatcache(); }
//this should include the file where the upper function exists include_once('download.php'); //and now list Downloads();
function Downloads($dir = '.') { //open current dir for reading.. $handle = @opendir($dir); //start the table where files are going to be listed.. echo '<table border="1" width="50%" style="border-collapse: collapse;" bordercolor="#000000" align="center"> <tr> <td width="40%" align="center"><b>File Name</b></td> <td width="30%" align="center"><b>File Size</b></td> <td width="30%" align="center"><b>Last Modified</b></td> </tr>'; //now loop through files.. while (false !== ($file = readdir($handle))) { //exclude the dots.. $ext = substr($file, -3); if ($file !== '.' && $file !== '..' and ($ext == 'gif' or $ext == 'jpg' or $ext == 'doc' or $ext == 'eps')) { //get file stats $info = stat($file); $stat1 = round($info['size'] / 1024, 2); $stat2 = date('j-n-Y H:i:s', $info['mtime']); echo '<tr> <td width="40%">'; echo "<a href=\"$file\">$file</a></td>\n\t"; echo ' <td width="30%" align="center">'.$stat1.' KB</td> <td width="30%" align="center">'.$stat2.'</td> </tr>'; } } echo '</table>'; //clear the cache.. clearstatcache(); }