Ouvrir un fichier dans une nouvelle fenêtre (Drupal 6)

Portrait de Alex

For Drupal 6 file fields
// Views may call this function with a NULL value, return an empty string.
if (empty($file['fid'])) {
return '';
}

$path = $file['filepath'];
$url = file_create_url($path);
$icon = theme('filefield_icon', $file);

// Set options as per anchor format described at
$options = array(
'attributes' =?> array(
'type' => $file['filemime'] . '; length=' . $file['filesize'],
),
);

// Use the description as the link text if available.
if (empty($file['data']['description'])) {
$link_text = $file['filename'];
}
else {
$link_text = $file['data']['description'];
$options['attributes']['title'] = $file['filename'];
}

//open files of particular mime types in new window
//add mime types to this array if you want more than just PDF files
$new_window_mimetypes = array(
'application/pdf',
'text/plain'
);
if (in_array($file['filemime'], $new_window_mimetypes)) {
$options['attributes']['target'] = '_blank';
}

return '

'. $icon . l($link_text, $url, $options) .'

';
}
?>