如何在使用PHP上傳多個文件時檢查上載PDF文件是否受密碼保護?如果密碼保護,我想顯示一個錯誤。如何檢查PDF文件是否受密碼保護或不在PHP
回答
我在網上發現了一個類似的文章檢查出來。
/**
* 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')));
}
}
}
這個問題的is it possible to check if pdf is password protected using ghostscript?的變化(你可能只需要執行只要shell腳本,它依賴於ghostcript)
您是否嘗試過考慮使用PHP執行shell腳本? 這將是很高興讓我知道我的答案已被低估的原因。 – 2013-04-09 12:20:04
嗨殼我沒有downvoted到你的答案,但我還是不明白如何使用你的引用腳本,請你解釋........ – Fairoz 2013-04-09 12:55:32
你可以執行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
- 1. 如何檢查文件是否受密碼保護/加密或不在java中
- 2. 檢查Excel文件是否受密碼保護
- 3. 檢查壓縮文件是否受密碼保護
- 4. 檢查pst文件是否受密碼保護
- 5. 檢查一個PDF文件是否有密碼保護
- 6. 如何將受密碼保護的PDF保存爲非密碼保護的PDF
- 7. 檢查代碼是否受到保護
- 8. 在SevenZipsharp(C#)中檢查檔案是否受密碼保護
- 9. 如何檢查Excel工作簿或工作表是否受密碼保護?
- 10. 如何創建受密碼保護的pdf文件
- 11. Excel VBA - 檢查工作表是否受密碼保護
- 12. hash_file如何在PHP中用於受密碼保護的文件?
- 13. 檢測受密碼保護的文檔
- 14. 如何在目錄中查找密碼保護的pdf文件?
- 15. 受密碼保護的PDF Jaspersoft
- 16. 如何使用php生成受密碼保護的csv文件
- 17. 檢查目錄是否受保護
- 18. 密碼保護在PHP中的pdf
- 19. 連接受密碼保護的文件
- 20. PDF文件的密碼保護
- 21. 打開密碼保護pdf文件
- 22. iTextsharp用長密碼保護PDF文件
- 23. 用密碼保護pdf文件c#
- 24. 在Android中的查看器中打開密碼受保護的PDF文件
- 25. 如何檢查文件/目錄是否爲受保護的OS文件?
- 26. 是否有.NET組件可以將XLS轉換爲受密碼保護的PDF?
- 27. 如何在C#中創建受密碼保護的文件
- 28. 如何在iPhone SDK中實現密碼保護的PDF文件
- 29. 如何使用applescript打開受密碼保護的PDF?
- 30. 如何打開受密碼保護的PPT和PDF
感謝您的快速回復,我已經測試這方法,但它不能正常工作。請告訴我任何其他方法......... – Fairoz 2013-04-09 12:14:58