DonB
|
Posted: 12/10/2005, 7:40 AM |
|
A more compact solution (and it also works when the filename is like
'foo.bar.jpg'):
function file_icon($file_name) {
$ext = array_pop(explode(".", $file_name)); # Get tail-end of the filename
if (strpos("|pdf|zip|txt|htm|html|xml|xsl|doc|csv|mp3|waw|swi|swf", $ext))
$file = $ext;
else if (strpos("|gif|jpg|png", $ext)) $file = "image";
else if (strpos("|php|cgi|asp", $ext)) $file = "script";
else if (strpos("|qt|mpg|mpeg", $ext)) $file = "movie";
else if (strpos("|sql" , $ext)) $file = "database";
else $file = "fileicon";
return "$file.gif";
}
--
DonB
http://www.gotodon.com/ccbth
"feha" <feha@forum.codecharge> wrote in message
news:25439aa3ff03cbe@news.codecharge.com...
>
> //====================================================
> function file_icon($file_name)
> {
> //by www.vision.to
>
> $ext=strrchr($file_name, ".");//Get file extention
> switch(strtolower($ext))
> {
> //assign particular icon
> //you can expand this as you need it ...
> case ".pdf": $file_icon = "pdf.gif"; break;
> case ".gif": $file_icon = "image.gif"; break;
> case ".jpg": $file_icon = "image.gif"; break;
> case ".png": $file_icon = "image.gif"; break;
> case ".zip": $file_icon = "zip.gif"; break;
> case ".txt": $file_icon = "txt.gif"; break;
> case ".php": $file_icon = "script.gif"; break;
> case ".htm": $file_icon = "htm.gif"; break;
> case ".html": $file_icon = "html.gif"; break;
> case ".xml": $file_icon = "xml.gif"; break;
> case ".xsl": $file_icon = "xsl.gif"; break;
> case ".xls": $file_icon = "xls.gif"; break;
> case ".doc": $file_icon = "doc.gif"; break;
> case ".csv": $file_icon = "csv.gif"; break;
> case ".asp": $file_icon = "script.gif"; break;
> case ".js": $file_icon = "js.gif"; break;
> case ".mp3": $file_icon = "mp3.gif"; break;
> case ".waw": $file_icon = "waw.gif"; break;
> case ".cgi": $file_icon = "script.gif"; break;
> case ".swi": $file_icon = "swi.gif"; break;
> case ".swf": $file_icon = "swf.gif"; break;
> case ".mov": $file_icon = "movie.gif"; break;
> case ".qt": $file_icon = "movie.gif"; break;
> case ".mpg": $file_icon = "movie.gif"; break;
> case ".mpeg": $file_icon = "movie.gif"; break;
> case ".sql": $file_icon = "database.gif"; break;
> default: $file_icon = "fileicon.gif";
>
> }
> return $file_icon;
> }
> //====================================================
>
>
> This is a function to assign icons depending on file extensions.
> You can use it in BeforeShow Event ...
>
> enjoy
>
> _________________
> Regards
> feha
> Vision.To Design
> www.vision.to
> wowdev.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|