Hi

I have many nodes with PDF attachments, which automatically open in Acrobat Reader when clicked. It would be really nice to make them open in a new window, or offer the 'Save file' dialogue instead. Otherwise, users can get engrossed in the PDF and not return to my site...

I'm just using the core Upload module, and External Links. External Links handles all normal URL links fine, but doesn't touch attachments.

Any thoughts welcomed - thanks! :)

Comments

pobster’s picture

Take a look at modules/upload/upload.module

/**
 * Implementation of hook_file_download().
 */
function upload_file_download($file) {

It returns a header in an array, if you add "Content-Disposition: attachment" to that list, then your pdf will open for download rather than in the current window. You'd need to check the mimetype to explicitly set that behaviour for pdfs though (you do have access to $file->filemime within that function so it's not a problem). If you've only got pdfs as attachments then just change it anyway.

I know it's not ideal to change a core function, but as long as you remember to make the change again if you upgrade Drupal then everything will be fine ;o)

Pobster

Jason Dean’s picture

That's great - thanks!

pmajum1’s picture

I have write the code in the core upload module as you have suggested but that does not work for me.
I am using Drupal 6 installation. please suggest me how could i do it.

jsolanaGBT’s picture

I don't know if you still need this, but just in case, I have Drupal 6.6 and it worked for me adding that line:

return array(
'Content-Type: ' . $file->filemime,
'Content-Length: ' . $file->filesize,
'Content-Disposition: attachment',
);

Thanks!