欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

如何设置pdf文件的下载链接?

问问题
 

我需要在我的节点(Drupal 7)中显示一个链接,并可以直接由访客用户下载?有任何模块可用或与视图一起工作吗?谢谢。

分享改善这个问题
 

4答案 正确答案

启用“文件”模块(它由drupal distr提供)。然后转到内容类型(在结构中),添加新内容类型或选择on。保存内容类型后,请参阅“管理字段”。添加新字段(填充标签和字段名称),选择类型=文件,单击保存。然后在extenstions填写pdf,并输入存储的地方。
现在尝试创建此内容类型,pdf文件上传将可用,保存后,您可以看到直接链接下载它,如果没有看到它,请访问内容类型并选中“管理显示”选项卡。

分享改进这个答案
 
   
感谢您的答案,是的工作上传文件,但文件的url未显示。我使用不同的方法通过ftp上传文件,然后使更改CHMOD公共文件夹文件可用。在节点中插入url,然后它也工作。 -  kuslahne 月在6:54 10 '11
   
嗯,它应该工作,检查你的权限和检查是节点编辑时上传的文件。 -  Nikit 月在7:37 10 '11

这个代码是在type ='file_managed'控制中的form api形式。

 $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)));
分享改进这个答案
 

我设法使用下面的代码来处理Drupal 6中的事情:

$path = 'sites/default/files/' . $name;

file_transfer($path, array(
  'Content-Type:application/pdf',
  'Content-Disposition:attachment; filename="' . $name . '"',
  'Content-Length:' . filesize($path)
));
分享改进这个答案
 

除了Nikit提到的内容之外,您还可以操纵现有的内容类型,向“基本页面”添加一个类型为“file”的可选字段(遵循相同的步骤)。然后任何你想要的是可以直接下载在该页面上。还有一个称为DownloadFile的drupal模块
 

 

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.

shareimprove this question
 

4 Answers 正确答案

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..

shareimprove this answer
 
   
Thanks 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. – kuslahne Oct 10 '11 at 6:54
   
hmm, it should work, check your permissions and check is file uploaded at node editing time. – Nikit Oct 10 '11 at 7:37

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)));
shareimprove this answer
 

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)
));
shareimprove this answer
 

In addition to what Nikit mentioned, you can also manipulate an existing content type, adding an optional field of type 'file' to, say, "basic page" (following the same procedure). Then whatever you want is directly downloadable on that page. There is also a drupal module called DownloadFile.


来自  http://stackoverflow.com/questions/7708452/how-do-i-setup-download-links-for-pdf-files


普通分类: