使用PHP删除PDF密码
我看到了一个我认为是解决办法的建议。然而,我似乎无法将该命令集成到我已经在工作的代码中。这是我用来抓取附件的函数使用PHP删除PDF密码,php,pdf,Php,Pdf,我看到了一个我认为是解决办法的建议。然而,我似乎无法将该命令集成到我已经在工作的代码中。这是我用来抓取附件的函数 public function saveAttachment ($message_id, $attachment, $filepath = null) { if(empty($filepath)){ return false; } if ($this->imap) { // Grab email
public function saveAttachment ($message_id, $attachment, $filepath = null) {
if(empty($filepath)){
return false;
}
if ($this->imap) {
// Grab email structure
$structure = imap_fetchstructure($this->imap, $message_id, FT_UID);
if (!$structure) {
return false;
} else {
// Grab body
$body = imap_bodystruct($this->imap, imap_msgno($this->imap, $message_id), ($attachment['section'] + 1));
// Grab attachemnt file and save it to location
$whandle = fopen($filepath ,'w');
stream_filter_append($whandle, 'convert.base64-decode', STREAM_FILTER_WRITE);
$save_result = imap_savebody($this->imap, $whandle, $message_id, ($attachment['section'] + 1), FT_UID | FT_PEEK);
fclose($whandle);
/** NEED HELP
$parts = explode("/",$filepath);
$part = end($parts);
$directory = str_replace("","",$parts)
chdir($directory);
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile='".$part."' -c .setpdfwrite -f '".$part."'";
$result = shell_exec($cmd);**/
return $save_result;
}
} else {
return false;
}
}
注释掉的部分是我用来从PDF附件中删除密码保护的代码。它就是不工作,所以我想我必须提供错误的路径?有什么明显的遗漏吗?可能的重复