Swift_Attachment-如何获取附件文件的路径

时间:2018-07-06 11:32:30

标签: laravel-5.5 swiftmailer

使用Swift_Attachment API可以获取文件名getFilename(),但是找不到找到文件完整路径的方法。

我正在使用Laravel 5.5和this email_log library,但需要对其进行修改,以使文件不存储在数据库中。

我已经使用Swift_Message->getChildren()到达了附件,里面有

-body: Swift_ByteStream_FileByteStream { 
  ...
  -path: "/root/path/to/my/file"
  ...
}

如果我可以将-body作为Swift_ByteStream_FileByteStream实例,那么可以使用here中的getPath(),但我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

决定存储附件中的文件,而不是路径中的文件,因为我找不到提取路径的方法。

    $messageId = strtok($message->getId(), '@');
    foreach ($message->getChildren() as $child) {
        $attachmentPath = 'email_log_attachments/' . $messageId . '/' . $child->getFilename();
        Storage::put($attachmentPath,$child->getBody());
    }