File listings with images and file sizes
Moderator: General Moderators
File listings with images and file sizes
Hey, I'm trying to make a page that lists the files in a certain folder, but also shows an image for each file type, tells the file type, and shows the file size. I have the list part down at http://brin.ath.cx/ but I cant get it to show the file size or anything else. Please help. The PHP file that lists the files is at http://brin.ath.cx/ . Thanks
cant you just use filesize() to get the size and output it?
http://www.php.net/manual/en/function.filesize.php
-enygma
http://www.php.net/manual/en/function.filesize.php
-enygma
This is a piece of code I use, it is modified from PHPNuke.
Code: Select all
function displaydir($Co=null,$UserDir=null,$Company=null)
{
Global $cookie;
$basedir = $Co;
$wdir = $UserDir;
global $udir;
global $lastaction;
$lastaction = "Listing directory";
$iconget = "<IMG src="images/disk.jpg" alt="Click to download" border="0">";
echo "<TABLE BORDER="0" cellspacing="1" cellpadding="0" width="500">";
print "<tr><td colspan="5" class="rightnav-links">To download a file click on <IMG src="images/disk.jpg" alt="Click to download" border="0" height="20" width="20"> next to your file</td></tr>";
print "<tr><td colspan="5" class="rightnav-links">To delete a file click on <img src="images/delete.jpg" alt="Delete $file" border="0" height="20" width="20"> next to your file</td></tr>";
print "<tr><td colspan="5"> </td></tr>";
echo "<tr>";
echo "<td class="directory-intsite">Type</th>";
echo "<td class="directory-intsite">Name</th>";
echo "<td class="directory-intsite">Size</th>";
echo "<td class="directory-intsite">Modified</th>";
echo "<td class="directory-intsite">Action</th>";
echo "</tr>";
//print "Base: $basedir User: $wdir";
//print $basedir . $wdir;
chdir($basedir . $wdir);
$handle=opendir(".");
while ($file = readdir($handle))
{
if(is_dir($file)) $dirlistї] = $file;
if(is_file($file)) $filelistї] = $file;
}
closedir($handle);
if($filelist)
{
asort($filelist);
while (list ($key, $file) = each ($filelist))
{
if (ereg(".gif|.jpg",$file))
{
$icon = "<IMG src="images/image.gif" alt="Image" border="0">";
$browse = "1";
$raw = "0";
$image = "1";
}
elseif (ereg(".txt|.dat",$file))
{
$icon = "<IMG src="images/paper.jpg" alt="Text" border="0">";
$browse = "1";
$raw = "1";
$image = "0";
}
elseif (ereg(".wav|.mp2|.mp3|.mp4|.vqf|.midi",$file))
{
$icon = "<IMG src="images/audio.gif" alt="Audio" border="0">";
$browse = "1";
$raw = "0";
$image = "0";
}
elseif (ereg(".phps|.php|.php2|.php3|.php4|.asp|.asa|.cgi|.pl|.shtml",$file))
{
$icon = "<IMG src="images/webscript.gif" alt="Web program" border="0">";
$browse = "1";
$raw = "1";
$image = "0";
}
elseif (ereg(".htaccess",$file))
{
$icon = "<IMG src="images/security.gif" alt="Apache Webserver security settings" border="0">" ;
$browse = "0";
$raw = "1";
$image = "0";
}
elseif (ereg(".html|.htm",$file))
{
$icon = "<IMG src="images/webpage.gif" alt="Web page" border="0">";
$browse = "1";
$raw = "1";
$image = "0";
}
else
{
$icon = "<IMG src="images/unknown.jpg" alt="Unknown filetype" border="0">";
$browse = "1";
$raw = "1";
$image = "0";
}
$filename=$basedir.$wdir.""e;.$file;
$fileurl=rawurlencode($wdir.$file);
$fileurl2=rawurlencode($udir.$wdir.$file);
$lastchanged = filemtime($filename);
$changeddate = date("d-m-Y H:i:s", $lastchanged);
echo "<TR>";
echo "<TD align="center" nobreak>";
echo "$icon</TD>
";
echo "<TD nobreak class="filename">". htmlspecialchars($file)."</TD>
";
echo "<TD align="right" nobreak class="filedetail">" . display_size($filename) . "</TD>";
echo "<TD align="middle" nobreak class="filedetail">" .$changeddate;
echo "</TD><TD nobreak>";
if($browse == "1")
{
echo " <A HREF="../../datadownload/$Company$wdir/$file">$iconget</A> ";
echo "<A HREF="download.php?op=del&wdir=$Company$wdir&file=$file"><img src="images/delete.jpg" alt="Delete $file" border="0"></A> ";
}
}
}
echo "</TD></TR></TABLE>";
}
function display_size($file){
$file_size = filesize($file);
if($file_size >= 1073741824)
{
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
}
elseif($file_size >= 1048576)
{
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
}
elseif($file_size >= 1024)
{
$file_size = round($file_size / 1024 * 100) / 100 . "k";
}
else{
$file_size = $file_size . "b";
}
return $file_size;
}Whats all that?
I guess im only good with if statements...lol.....btw, i already looked at the manual for filesize() but thats why i asked for help, i wish they gave examples. I'll try to underastand all of that code, but in case....can anyone give me a 'snipit' of code on how to get the file size of a file called....oh say....bob.html
Thanks guys!
Thanks guys!