2013-05-14 53 views
0

文件下載彈出的形式我是新來的Drupal。我想創建一個名稱,電子郵件字段,下載和關閉按鈕的彈出的形式,當用戶點擊下載鏈接彈出的形式要顯示,然後用戶給出的姓名和電子郵件驗證後的文件已經下載的用戶,也多少用戶已經下載了我怎麼能點他如何創建drupal7

回答

1

您可以使用Webform protected downloads模塊,提示用戶下載該文件之前,以填補ATLEAST電子郵件領域。您可以添加任意數量的文件。請參閱此答案Fill form before download

如果要手動執行此操作,請創建一個帶有必要字段的webform,並且您可以使用hook_form_alter。在你template.php中,

function YOUR_THEME_form_alter(&$form, &$form_state, $form_id){ 
     if($form_id == "YOUR_WEBFORM_ID") 
     { 
      $form['#submit'][] = 'download_file'; 
     } 
    } 

    function download_file(){ 

     $file_path = variable_get('file_public_path', conf_path() . '/files'); 
     $file_name = $file_path."/YOUR_FILE"; 
     $file = fopen($file_name, 'r'); 
     $file_size = filesize($file_name); 

     header("Content-type: application/pdf"); // add here more headers for diff. extensions 
     header("Content-Type: application/force-download"); 
     header("Content-Type: application/download"); 
     header("Content-Description: File Transfer"); 
     header("Content-Disposition: attachment; filename=\"". urlencode('FILENAME')."\""); // use 'attachment' to force a download 
     header("Content-length: $file_size"); 
     header("Cache-control: private"); //use this to open files directly 
     while(!feof($file)) { 
      $buffer = fread($file, 2048); 
      echo $buffer; 
      flush(); 
     } 
     $url = $_SERVER['REQUEST_URI']; 
     header('Location:'. $url); 
     fclose ($file); 
} 

這將下載提交表單的文件。

要使表單彈出,請在表單設置下將表單設置爲塊,然後將表單塊放入任何jQuery插件,如thickbox

+0

漂亮的代碼,這在Drupal鉤必需的。但是這個概率是在文件下載控制無法重新形成之後。對這個問題有任何有價值的建議。 – Bharanikumar 2014-11-03 14:27:51

+0

有興趣同樣的事情,你@Bharanikumar,也是我需要從管理員添加的文件,你知不知道這樣做的方法嗎? – Ionut 2017-04-13 07:06:22