如何检查是否一个PDF文件密码保护PHP或不[关闭](How to check if a PDF f

2019-08-20 22:48发布

我如何检查是否上传PDF文件的密码保护或不同时使用PHP上传多个文件? 我想说明一个错误,如果它的密码保护。

Answer 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')));
          }
        }
     }


Answer 2:

这个问题是一个变化是有可能检查PDF使用ghostscript的密码保护? (你可能只需要执行只要shell脚本,这依赖于ghostcript)



文章来源: How to check if a PDF file is password protected or not in PHP [closed]