Saving a Base64 string to disk as a binary using PHP(使用 PHP 将 Base64 字符串作为二进制文件保存到磁盘)
问题描述
作为我自己的深入了解"教程,我正在构建一个 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内容传输编码:base64X 附件 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/4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAAUAAAABAAAAYgEbAAUAAAABAAAAageEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp
/9j/4AAQSkZJRgABAgEASABIAAD/4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp
(...)
EAgEAgEAgEAgEAg8IBQRL/Lbe/tJrScHqZ2lkmE4XUP2XcSDZZ2VvZ28dtbsDIYmhkbRxAIJCAQCAQCAQf/ScyAQCAQCAQCAQCAQCAQCAQCAQCAQCAQf/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_decode() 到获取二进制数据,使用 file_put_contents()
Pass the data to base64_decode() to get the binary data, write it out to a file with file_put_contents()
这篇关于使用 PHP 将 Base64 字符串作为二进制文件保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 将 Base64 字符串作为二进制文件保存到磁盘
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
