Can't open downloaded attachments from Gmail API
I feel like I'm missing something stupid... I'm using the PHP SDK for the new Gmail API to fetch an attachment from an email. I can get the attachment content, but unless it's a text file, I can't open the file after it's been saved. If the attachment is a PDF, it won't render. If it's an excel file, it won't open. What am I doing wrong? // this works; I get the attachment body, etc $data = $g->gmail->users_messages_attachments->get($email_account, $email_message_id, $p->getBody()->getAttachmentId()); $fh = fopen(DOC_ROOT."/file.pdf", "w+"); fwrite($fh, base64_decode($data->data)); fclose($fh)