Web Hosting Talk







View Full Version : Php help. Php to show contents of a directory


impudicity
12-04-2002, 07:50 PM
Hey,
I just recently converted my site to php. I havnt worked with php in a while, so I forgot alot. Anyways, how would I go about using php to show the files in a certain directory with the file size next to it? Example: I upload, something.mp3 and on one of my pages it would show:
something.mp3 17392 bytes or whatever. And if I upload somethingagain.mp3 it will automaticly list it.
I hope this makes sence.
Thanks

impudicity
12-04-2002, 08:43 PM
Never mind, I got it. And I guess i'll post it incase someone else would be interested in it:

$directory = 'directory path';
$Open = opendir ($directory);
$i=0;
$Tot_Size=0;
while ($Files = readdir ($Open))
{
$Filename = "$directory/".$Files;
if (is_file($Filename))
if(strchr($item,"."))
{
continue;
}
else
{
$i++;
$Size = filesize("$directory/$Files");
$Tot_Size = $Tot_Size + $Size;
echo "<a href=songs/$Files><font class=\"small\">$Files</font></a> </td><td align=\"right\"> <font class=\"small\">$Size</font> </td>";
echo '</tr><tr><td>';
}
}
echo'</tr><tr><td>';
echo"\n</td></tr></table>\n";
echo "<font class=\"tiny\">Files available - $i<br>Total Size - $Tot_Size bytes</font>";
echo "\n</td></tr></table>";