How do I setup download links for pdf files?
Solution 1
Enable "File" module (it's provided by drupal distr). Then goto 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 extenstions 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..
Solution 2
I managed to get things going in Drupal 6 using the following code:
$path = 'sites/default/files/' . $name;
file_transfer($path, array(
'Content-Type:application/pdf',
'Content-Disposition:attachment; filename="' . $name . '"',
'Content-Length:' . filesize($path)
));
Solution 3
This code is form api form in type='file_managed' control.
$path = 'Please Provide a full file path or file uri path Ex:- public://file.pdf.';
file_transfer($path, array('Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="' . 'Please set a file name EX:- basename($path);'. '"',
'Content-Length' => filesize($path)));
Comments
-
kuslahne over 3 years
I need to show a link in my node (Drupal 7) and can be download directly by guest user? Is there any module available or work with view? Thanks.
-
kuslahne over 12 yearsThanks for your answer, yes it works for uploading file but the url to file not shown. I am using different approach by upload files via ftp then make the public folder file available with change CHMOD. Insert the url in node then it also works.
-
Nikit over 12 yearshmm, it should work, check your permissions and check is file uploaded at node editing time.