3

使用 PHP 上传多个文件时,如何检查上传 PDF 文件是否受密码保护?如果它受密码保护,我想显示一个错误。

4

2 回答 2

2

我在网上找到了一个类似的帖子,检查一下。

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')));
          }
        }
     }
于 2013-04-09T12:07:13.007 回答
0

这个问题是是否可以使用ghostscript检查pdf是否受密码保护的变体?(您可能只需要执行那里提供的 shell 脚本,它依赖于 ghostcript )

于 2013-04-09T12:07:48.513 回答