Wednesday, April 22, 2009

Open uploaded pdf files in other browser tab with drupal

As in MAC OS and Linux the uploaded file in drupal site is default open with Save As Dialog box, but where as in Windows the pdf file is open in current browser window.

To Open that pdf in other window

In the core upload module of Drupal go to modules/upload/upload.module is where you will find the function theme_upload_attachments() as follows:

function theme_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));
if (
count($rows)) {
theme('table', $header, $rows, array('id' => 'attachments'));

In this function change

$rows[] = array(l($text, $href), format_size($file->filesize));


$rows[] = array(l($text, $href, array('attributes' => array('target' => '_blank'))), format_size($file->filesize));

And you can get files are being open in other browser tab rather than current browser window.

No comments: