Click to See Complete Forum and Search --> : custom icon for file type


Annaccond
05-10-2007, 07:05 PM
I have such script for showing list of files and directories on my server:

<?php
function showContent($path){

if ($handle = opendir($path))
{
$up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
echo "<tr><td colspan='3'>";
echo "<a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a>";
echo "</td></tr>";

while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fName = $file;
$file = $path.'/'.$file;

if(is_file($file)) {
echo "<tr><td> -F- <a href='".$file."'>".$fName."</a></td>"
."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>"
."<td align='right'>".filesize($file)." bytes</td></tr>";
} elseif (is_dir($file)) {
print "<tr><td colspan='3'> -D- <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
}
}
}

closedir($handle);
}

}
?>

Can I add some script which would add custom icon dependently from file type (it would in place where "-F-" is right now)? I'd like to have different icon for images, audio files, archives etc. so I seems to need a script which would recognize file type and add suitable icon. I'll be grateful for tips and help.

kurniawan
05-10-2007, 08:06 PM
First, determine the file type with this function http://jp.php.net/manual/en/function.finfo-file.php then use str_replace() to replace -F- in your script.

---------------------------------------
http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
http://ppi-kansai.net http://kti2007.ppi-kansai.net

Annaccond
05-10-2007, 09:16 PM
I have problems with finfo. I would appreciate if someone could help me write correct script for it.

LeeU
05-11-2007, 10:33 AM
I believe this (http://www.hunlock.com/blogs/Attach_icons_to_anything_with_CSS) is what you are looking for.

Annaccond
05-13-2007, 07:17 PM
Thank you very much LeeU! It working very easy and giving me exactly effect which I needed. Thanks once again :)

LeeU
05-14-2007, 09:12 AM
Glad I could help. You might want to thank the author also.