3

enter image description here

I want to add a pdf file via a file field on a content type, I want to display a download link, and if the user clicks save it to your computer, as in a normal download.

  • Do you mean stop the browser/operating system from opening the file in a PDF viewer? If so, you can't - it's the user's choice whether or not that happens. If not, could you expand on what you'd like to do? Providing a download link for a file is what Drupal core does by default – Clive Sep 25 '13 at 18:12
  • I want to upload a pdf to the server, and that it has its download link and when clicking on that link will download as a normal download – daniel Sep 25 '13 at 18:19
  • Yep, I understand that. So what part of the standard method of adding a file field, which is displayed on the node as a link, isn't working for you? Also, exactly what do you mean by "normal download"? Please see my first comment concerning that, you can't override user's browser settings – Clive Sep 25 '13 at 18:20
  • look, I have a content type of document file type, then I want to upload the pdf, may have a link to download and save. As you do that? many thanks for your help – daniel Sep 25 '13 at 18:23
  • Can you just answer the questions I've asked please? They're not difficult ones to answer. It's not clear what you mean, or what you've already tried (have you added a file field to the content type, for example?). If you expand your question to give it enough detail so that someone who's never encountered your site would understand what you're asking, I'll be glad to answer if I can – Clive Sep 25 '13 at 18:24
3

Try the DownloadFile module. In your content type change the field display formatter to download file or whatever suits your need.

  • Good tip - I'm going to check this module out as it may be a more robust solution than what I mentioned below. Also, not everybody has write access to their site's .htaccess file, so it's good to know there's a module for this. – Anne Bonham Sep 25 '13 at 20:59
  • This does not provide Download button. Moreover it works using GET method. – AgA Sep 26 '13 at 5:14
0

If you have access to it, placing the following snippet in your site's .htaccess file will force download in many recent browsers, but Clive is correct: this won't work for everybody (due to user preferences and also not all devices and browsers obey this setting). The following syntax is for apache on LINUX, you may have to tweak it for a windows environment. I wish I knew how to get this to work on iPhones (if anybody knows - do tell!). I'm sure there is a much more elegant way to cover upper and lower case file extensions (hey - I'm making this up as I go along ; )

<FilesMatch "\.(mov|mp3|jpg|pdf|MOV|MP3|JPG|PDF)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>
0

Enable "File" module (it's provided by Drupal distr). Then go to content types (in Structure), add new content type or select on of exists.

After saving content type see "manage fields". Add new field (fill label and field name), select Type of this = File, click Save. Then in extensions fill PDF, and enter place of storing.

Now try create this content type, PDF file uploading will available and after saving you can see direct link to download it, if you don't see it, visit content type and check "Manage display" tab.

Taken from source https://stackoverflow.com/questions/7708452/how-do-i-setup-download-links-for-pdf-files

and also if you want to force the user to download only, then use this module File Force Download

File Force Download can be used to force the user's web browser to download the file to disk instead of displaying it in the browser window.

Web browsers today are pre-configured to render various types of media directly, such as text files, various image, video and audio formats, PDF documents, and Flash movies. While it is still possible to save such files afterwards by right-clicking on them and selecting "Save As..", it is sometimes desirable to just offer the file for download in the first place. File Force Download solves this issue by supplying a file with certain HTTP headers which instruct the web browser to download the file to the user's disk instead of displaying it in a browser window.

0

Note: i couldn't use File Force Download module since it only works off of fields... I had files uploaded with IMCE and I had regular links in content Body to those private files... So i had to use setting the header via apache's side via the httpd.conf or .htaccess with above answers ... You can do this with a module as well which is what I ended up going with:

<?php
function mymodule_mimetype_override_file_mimetype_mapping_alter(&$mapping) {  
  $new_mime_type = 'application/octet-stream'; //already in mimetypes so below array addition wont happen, but put here in case you want to add your own type

  if ( !in_array($new_mime_type, $mapping['mimetypes'])) {
    $mapping['mimetypes'][] = $new_mime_type; //mapping['mimetypes']['octetstream']
  }
  $index = array_search($new_mime_type, $mapping['mimetypes']);
  $mapping['extensions']['pdf'] = 15; //manually setting for now, could have used $index; //15 is octet-stream, 18 is pdf
}

//also added this for my HTTPS site since IE8 couldnt download/display any files if it doesn't have certain cache headers for ssl websites ... heh, booooooo
function mymodule_override_file_download($filepath) {
  header("Cache-Control: private, must-revalidate"); //may have to set Pragma too but not in my case
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.