保存Base64的字符串磁盘作为二进制使用PHP

保存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()