Drupal7, Coding

How to change/add custome file icon for uploaded files

In theme’s template.php file, we have to write below code :

function <theme-name>_file_icon($variables) {
global $base_url;
$file = $variables[‘file’];
$icon_directory = drupal_get_path(‘theme’, ‘<theme-name>’) . ‘/<file-icon-folder>’;
$mime = check_plain($file->filemime);
$icon_url = file_icon_path($file, $icon_directory);
$token = drupal_get_token(“file/{$file->fid}/download”);
return l(‘<img alt=”” class=”file-icon” src=”‘.$base_url.’/’.$icon_url . ‘” title=”‘ . $mime . ‘” />’ ,
“file/{$file->fid}/download” ,
array(
‘query’ => array(‘token’ => $token) ,
‘html’ => TRUE
)
);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s