如何在 PHP 中进行多文件上传时检测受密码保护的 PDF 文件 [已关闭]

问题描述 投票:0回答:1

我正在开发 PHP 中的一项功能,允许用户一次上传多个文件。这些文件中,可能有PDF文件。我想检查这些 PDF 文件是否受密码保护。如果 PDF 文件受密码保护,我想显示错误消息。我怎样才能在 PHP 中实现这一点?

php pdf passwords password-protection
1个回答
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')));
          }
        }
     }
© www.soinside.com 2019 - 2024. All rights reserved.