首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用PHP从Outlook下载附件?

如何使用PHP从Outlook下载附件?
EN

Stack Overflow用户
提问于 2019-11-03 16:08:37
回答 1查看 574关注 0票数 3

我想下载一个附件。我已收到附文,要求:

/me/message/{message_id}/attachments/{attachment_id}

答复如下:

代码语言:javascript
复制
[_propDict:protected] => Array
        (
            [@odata.context] => https://graph.microsoft.com/v1.0/$metadata#users('username')/messages('messageId')/attachments/$entity
            [@odata.type] => #microsoft.graph.fileAttachment
            [@odata.mediaContentType] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            [id] => xxx
            [lastModifiedDateTime] => 2019-11-02T17:50:52Z
            [name] => xxx.xlsx
            [contentType] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            [size] => 33459
            [isInline] => 
            [contentId] => f_k2hv435z0
            [contentLocation] => 
            [contentBytes] => GuzzleHttp\Psr7\Stream Object
                (
                    [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #374
                    [size:GuzzleHttp\Psr7\Stream:private] => 
                    [seekable:GuzzleHttp\Psr7\Stream:private] => 1
                    [readable:GuzzleHttp\Psr7\Stream:private] => 1
                    [writable:GuzzleHttp\Psr7\Stream:private] => 1
                    [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
                    [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                        (
                        )
                )
        )
)

这里不是sourceUrl,而是contentBytes。我能用contentBtyes做这个吗?怎么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-03 16:24:38

我认为$object->getContentBytes()应该为你工作。

UPD:如果您想将内容作为文件下载,您可以执行类似的操作:

代码语言:javascript
复制
$fileName = "download.txt";
$contents =  $object->getContentBytes(); // base64_decode() here if needed

header("Content-type: text/plain"); // Or any other format
header("Content-Disposition: attachment; filename=" . $fileName);
print $contents;
die;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58682015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档