File Type Icon Script/Function
Posted: Wed Dec 24, 2008 6:15 am
Guys,
I need some help one again. It's been a little while since I've called upon for help, but here it is...
I'm basically building a very, VERY simple file uploader for my site, so that at the spur of the moment, I can quickly upload a file or two to my webserver. I was going to add a few minor features, and one of them being a File Type Icon Script/Function, however, I'm not able to get it to work. Here's a few snippets of the related code:
The following is the array that basically says "for this extension, use this filename (for the image)":
The following is the function I am trying to code so that the extension can be called from the table (HTML):
The following is the HTML markup section (remember all these are snippets from my code, so don't worry about the variables):
Basically, the
Not sure though. If anyone can shed some light and help out, I would be much appreciated.
Thanks again,
Drew
I need some help one again. It's been a little while since I've called upon for help, but here it is...
I'm basically building a very, VERY simple file uploader for my site, so that at the spur of the moment, I can quickly upload a file or two to my webserver. I was going to add a few minor features, and one of them being a File Type Icon Script/Function, however, I'm not able to get it to work. Here's a few snippets of the related code:
The following is the array that basically says "for this extension, use this filename (for the image)":
Code: Select all
$filetypes = array (
'png' => 'jpg.gif',
'jpeg' => 'jpg.gif',
'bmp' => 'jpg.gif',
'jpg' => 'jpg.gif',
'gif' => 'gif.gif',
'zip' => 'zip.gif',
'rar' => 'rar.gif',
'exe' => 'exe.gif',
'setup' => 'setup.gif',
'txt' => 'text.png',
'htm' => 'html.gif',
'html' => 'html.gif',
'fla' => 'fla.gif',
'swf' => 'swf.gif',
'xls' => 'xls.gif',
'doc' => 'doc.gif',
'sig' => 'sig.gif',
'fh10' => 'fh10.gif',
'pdf' => 'pdf.gif',
'psd' => 'psd.gif',
'rm' => 'real.gif',
'mpg' => 'video.gif',
'mpeg' => 'video.gif',
'mov' => 'video2.gif',
'avi' => 'video.gif',
'eps' => 'eps.gif',
'gz' => 'archive.png',
'asc' => 'sig.gif',
'wma' => 'audio.jpg',
'mp3' => 'audio.jpg',
'unknown' => 'error.gif',
);
Code: Select all
// getIcon
function getIcon($ext) {
$icon = $ext;
if($filetypes[$icon]) {
$icon = $filetypes[$icon];
} else {
$icon = 'error.gif';
}
return $icon;
}
Code: Select all
<tr>
<td><img src="_resources/<?php echo getIcon($ext); ?>" /></td>outputs "rar" or "exe" or "zip" and so on, depending on the extension of each filename - this works. The part that doesn't is the function. Whenever I execute the code, it automatically just gets "error.gif" and displays it. I might be calling it wrong or my code just might be really messed up. I've even done some thorough testing to make sure that the PHP function itself is at least getting the extension. So I believe the part I am getting wrong is the following:$ext
Code: Select all
if($filetypes[$icon]) {Thanks again,
Drew