Version: v1.00

Type: Function

Category: File Management

License: Other

Description: My server don't like the mime content command so i used strrev and explode to determine the extension. I was just using a simple explode of '.' but if a file was like wappy.chat.V1.60 then i had obvious problems. Here is my (slightly long winded) fix ;-)



I used this simple function to determine the file extension of files on my site (as my server won't allow type and i was using just and explode command but more that one dot in the file gave obvious problems) so i can put a unique icon next to each file thats listed. If you would like the icons (they are very small as designed for mobile/wap sites) you can get them at my wap site http://cult.toddywap.com
<?
//icon code
$file_name = "wappy.zip";

//set a unknown icon as default
$icon = "unknown.gif";

//reverse the file name
$rev = strrev ($file_name);

//explode reversed name
$exp = explode (".", $rev);

//the true ext is the $exp[0]reversed
$true = strrev ($exp[0]);

//make the letters small so no need for more code to match gif Gif GIF etc...
$trueext = strtolower ($true);

//set the file types to the icons 
if ($trueext=="zip" OR $trueext=="rar" OR $trueext=="gz"){$icon = "zip.gif";}
if ($trueext=="amr"){$icon = "amr.gif";}
if ($trueext=="midi"){$icon = "midi.gif";}
if ($trueext=="mid"){$icon = "mid.gif";}
if ($trueext=="gif"){$icon = "gif.gif";}
if ($trueext=="jpeg"){$icon = "jpeg.gif";}
if ($trueext=="jpg"){$icon = "jpg.gif";}
if ($trueext=="jad"){$icon = "jad.gif";}
if ($trueext=="jar"){$icon = "jar.gif";}
if ($trueext=="sis"){$icon = "sis.gif";}
if ($trueext=="bmp"){$icon = "bmp.gif";}
if ($trueext=="wbmp"){$icon = "wbmp.gif";}
if ($trueext=="txt"){$icon = "txt.gif";}
if ($trueext=="avi"){$icon = "avi.gif";}
if ($trueext=="thm"){$icon = "thm.gif";}
if ($trueext=="nth"){$icon = "nth.gif";}
if ($trueext=="png"){$icon = "png.gif";}
if ($trueext=="mmf"){$icon = "mp4.gif";}
if ($trueext=="wav"){$icon = "wav.gif";}

//you will obviously need to mod this slightly to your script, i used it for a WAP/mobile based file share ;-)
?>