7 file.module theme_file_icon($variables)

Returns HTML for an image with an appropriate icon for the given file.


$variables: An associative array containing:

  • file: A file object for which to make an icon.
  • icon_directory: (optional) A path to a directory of icons to be used for files. Defaults to the value of the "file_icon_directory" variable.

Related topics

1 theme call to theme_file_icon()
theme_file_link in modules/file/file.module
Returns HTML for a link to a file.
2 string references to the theme hook from theme_file_icon()

Note: this list is generated by looking for the string for this theme hook, so it may include some references that are not actually using this theme hook.

file_theme in modules/file/file.module
Implements hook_theme().
theme_file_link in modules/file/file.module
Returns HTML for a link to a file.


modules/file/file.module, line 785
Defines a "managed_file" Form API field and a "file" field for Field module.


function theme_file_icon($variables) {
  $file = $variables ['file'];
  $icon_directory = $variables ['icon_directory'];

  $mime = check_plain($file->filemime);
  $icon_url = file_icon_url($file, $icon_directory);
  return '<img class="file-icon" alt="" title="' . $mime . '" src="' . $icon_url . '" />';


When working with file icons I noticed 2 annoying things.
1) The file icons do not include alt or title tags
2) The src is a relative URL instead of a fully qualified URL so if you have a file icon being displayed in an RSS feed, when that RSS feed is displayed in someone's email the icon is broken because it does not include the domain name.

Here is a quick fix that can be used to address both of those issues:

function yourthemename_file_icon($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
$mime = check_plain($file->filemime);
$icon_url = file_icon_url($file, $icon_directory);
return '';

Hope this helps someone looking at this hook and wondering how that might be done :-)