Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP删除PDF密码_Php_Pdf - Fatal编程技术网

使用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附件中删除密码保护的代码。它就是不工作,所以我想我必须提供错误的路径?有什么明显的遗漏吗?

可能的重复