1

I saw one suggestion in this thread which I believe is the solution. However, I can't seem to integrate that command to my already-working code. This is the function I use to grab the attachments.

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;
    }
}

The commented out section is the code I use to remove the password protection from a PDF attachment. It just doesn't work so I guess I must supply the wrong path? Is there anything obvious that I missed?

Community
  • 1
  • 1
nogias
  • 563
  • 2
  • 6
  • 23
  • Possible duplicate of [php shell\_exec() command is not working](http://stackoverflow.com/questions/20124327/php-shell-exec-command-is-not-working) – Ben Simmons Jan 14 '16 at 05:28

0 Answers0