我在this thread中看到了一个我认为是解决方案的建议。但是,我似乎无法将该命令集成到我已经运行的代码中。这是我用来抓取附件的功能。
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附件中删除密码保护的代码。它只是不起作用所以我想我必须提供错误的路径?我错过了什么明显的东西?