Theming the regular File-Upload Link

The following snipplet added to your theme's template.php adds a

target="_blank"

to any file upload link on your page:

 

function mytheme_upload_attachments($files) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($files as $file) {
$file = (object)$file;
if ($file->list && empty($file->remove)) {
$href = file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
# $rows[] = array(l($text, $href), format_size($file->filesize));
$options=array(
'attributes'=>array(
'target'=>'_blank'
),
'html'=>'true'
);
$rows[] = array(l($text, $href, $options), format_size($file->filesize));
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}

»