保存Base64的字符串磁盘作为二进制使用PHP [英] Saving a Base64 string to disk as a binary using PHP

查看:239
本文介绍了保存Base64的字符串磁盘作为二进制使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为看在幕后的教程为我自己我建立一个PHP脚本从POP3邮箱收集邮件。在尝试使用二进制附件的我被困试图找出如何处理附件信息做的。

As a "look under the covers" tutorial for myself I am building a PHP script to gather emails from a POP3 mailbox. While attempting to make use of binary attachments I am stuck trying to figure out what to do with the attachment information.

由于会从电子邮件中收集的字符串:

Given a string that would be gathered from an email:

------ = _ Part_16735_17392833.1229653992102
  内容类型:图像/ JPEG;名称= trans2.jpg
  内容传输编码:BASE64
  的X附件-ID:f_fow87t5j0
  内容处置:附件;文件名= trans2.jpg

------=_Part_16735_17392833.1229653992102 Content-Type: image/jpeg; name=trans2.jpg Content-Transfer-Encoding: base64 X-Attachment-Id: f_fow87t5j0 Content-Disposition: attachment; filename=trans2.jpg

/ 9j中/ 4AAQSkZJRgABAgEASABIAAD / 4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA
  AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp

/9j/4AAQSkZJRgABAgEASABIAAD/4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp

(...)

EAgEAgEAgEAgEAg8IBQRL / LBE / tJrScHqZ2lkmE4XUP2XcSDZZ2VvZ28dtbsDIYmhkbRxAIJCAQC
  AQCAQf / ScyAQCAQCA​​QCA​​QCA​​QCA​​QCA​​QCA​​QCA​​QCA​​Qf / 9K =
  ------ = _ Part_16735_17392833.1229653992102 -

EAgEAgEAgEAgEAg8IBQRL/Lbe/tJrScHqZ2lkmE4XUP2XcSDZZ2VvZ28dtbsDIYmhkbRxAIJCAQC AQCAQf/ScyAQCAQCAQCAQCAQCAQCAQCAQCAQCAQf/9k= ------=_Part_16735_17392833.1229653992102--

有没有办法将数据保存往磁盘,这样它会在可用的格式?

Is there a way to save off the data to disk so that it would be in a usable format?

推荐答案

数据传递到 base64_de code()获得二进制数据,写出来与的file_put_contents的文件()

Pass the data to base64_decode() to get the binary data, write it out to a file with file_put_contents()

这篇关于保存Base64的字符串磁盘作为二进制使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆