/    Sign up×
Community /Pin to ProfileBookmark

custom icon for file type

I have such script for showing list of files and directories on my server:

[code=php] <?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);
}

}
?> [/code]

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.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@kurniawanMay 11.2007 — 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
Copy linkTweet thisAlerts:
@AnnaccondauthorMay 11.2007 — I have problems with finfo. I would appreciate if someone could help me write correct script for it.
Copy linkTweet thisAlerts:
@LeeUMay 11.2007 — I believe this is what you are looking for.
Copy linkTweet thisAlerts:
@AnnaccondauthorMay 14.2007 — Thank you very much [B]LeeU[/B]! It working very easy and giving me exactly effect which I needed. Thanks once again ?
Copy linkTweet thisAlerts:
@LeeUMay 14.2007 — Glad I could help. You might want to thank the author also.
×

Success!

Help @Annaccond spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...