How to check if a PDF file is password protected or not in PHP(如何在 PHP 中检查 PDF 文件是否受密码保护)
本文介绍了如何在 PHP 中检查 PDF 文件是否受密码保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用 PHP 上传多个文件时,如何检查上传 PDF 文件是否受密码保护?如果它受密码保护,我想显示一个错误.
How can I check if uploading a PDF file is password protected or not while uploading multiple files using PHP? I want to show an error if it's password protected.
推荐答案
我在网上找到了一个类似的帖子,看看.
i found a similiar post on the web check it out.
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')));
}
}
}
这篇关于如何在 PHP 中检查 PDF 文件是否受密码保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在 PHP 中检查 PDF 文件是否受密码保护


猜你喜欢
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Laravel 仓库 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01