filename to icon


/ Published in: PHP
Save to your folder(s)

works with fugue icons, but can be custumized


Copy this code and paste it in your HTML
  1. function extensionToIcon($filename)
  2. {
  3. $filename = strtolower($filename);
  4. $ext = strtolower(substr($filename,strrpos($filename,".")));
  5. $icnext = "png";
  6. if(strrpos($_SERVER['HTTP_USER_AGENT'],"MSIE 6.0"))
  7. {
  8. $icnext = "gif";
  9. }
  10. if($ext == ".pdf")
  11. {
  12. return "document_text_image.$icnext";
  13. }
  14. else if(in_array($ext,array( ".mov" , ".flv" , ".avi" , ".mpeg" , ".mpg" , ".wmv", ".mp4",)))
  15. {
  16. return "film.$icnext";
  17. }
  18. else if(in_array($ext,array( ".mp3" , ".aac" , ".wav" , ".wma" ,)))
  19. {
  20. return "music_beam_16.$icnext";
  21. }
  22. else if(in_array($ext,array( ".jpg" , ".jpeg" , ".png" , ".gif" , ".bmp" ,)))
  23. {
  24. return "image.$icnext";
  25. }
  26. else if(in_array($ext,array( ".txt" , ".rtf" ,)))
  27. {
  28. return "document_text.$icnext";
  29. }
  30. else if(in_array($ext,array( ".doc" , ".docx" ,)))
  31. {
  32. return "document_word_text.$icnext";
  33. }
  34. else if(in_array($ext,array( ".xls" ,)))
  35. {
  36. return "document_excel_table.$icnext";
  37. }
  38. else if(in_array($ext,array( ".sql" , ".mdb")))
  39. {
  40. return "database.$icnext";
  41. }
  42. else if(in_array($ext,array( ".zip" , ".7z" , ".rar" , ".gz" , ".tar")))
  43. {
  44. return "document_zipper.$icnext";
  45. }
  46. else if($ext == $filename)
  47. {
  48. return "folder_horizontal_open.$icnext";
  49. }
  50. else
  51. {
  52. return "document.$icnext";
  53. }
  54. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.