2013-04-09 157 views

回答

1

我在網上發現了一個類似的文章檢查出來。

http://drupal.org/node/843516

/** 
* Check whether pdf is encrypted or password protected. 
* @param <type> $form 
* @param <type> $form_state 
*/ 
function pdftest_is_encrypted($form,&$form_state) {  
    include_once 'sites/all/libraries/fpdi/pdf_parser.php';  
    foreach($form_state['values']['files'] as $value) { 
     //Check whether file type is pdf and confirm the file is selected to remove. 
     if($value['filemime'] == 'application/pdf' && $value['remove'] != 1) { 
      $pdf = new pdf_parser($value['filepath']);     
      if(stristr($pdf->errormsg,'File is encrypted')) { 
       form_set_error('field_attachment', t('Uploaded PDF Document '.$value['filename'].' is encrypted and can not be uploaded. '.l('Guide to troubleshooting failed uploads.','http://support.scribd.com/forums/33627/entries/24412'))); 
      } 
     } 
    } 
+0

感謝您的快速回復,我已經測試這方法,但它不能正常工作。請告訴我任何其他方法......... – Fairoz 2013-04-09 12:14:58

0

這個問題的is it possible to check if pdf is password protected using ghostscript?的變化(你可能只需要執行只要shell腳本,它依賴於ghostcript)

+0

您是否嘗試過考慮使用PHP執行shell腳本? 這將是很高興讓我知道我的答案已被低估的原因。 – 2013-04-09 12:20:04

+0

嗨殼我沒有downvoted到你的答案,但我還是不明白如何使用你的引用腳本,請你解釋........ – Fairoz 2013-04-09 12:55:32

+0

你可以執行shell腳本,你會發現在另一個問題的接受答案中使用本機函數「exec」。 爲此,在將路徑傳遞給「exec」之前,需要腳本的執行權限。另一個要求是在你的機器上安裝ghostscript,這是shell腳本所要求的。檢查「exec」返回的值會告訴你PDF文件是否受密碼保護。例如' $ results = array(); exec('path_to_shell_script file.pdf',$ results);的print_r($結果); ' – 2013-04-09 13:47:56