PHP base64 encode a pdf file(PHP base64编码pdf文件)
问题描述
我正在使用一个 API,我可以在其中将文档发送到 Dropbox 之类的东西.根据文档,发送的文件需要是BASE64编码的数据.
I am using an API where I can send a document to something like dropbox. According to the documentation, the file which is sent needs to be BASE64 encoded data.
因此,我正在尝试这样的事情
As such, I am trying something like this
$b64Doc = chunk_split(base64_encode($this->pdfdoc));
$this->pdfdoc 是我的 PDF 文档的路径.
Where $this->pdfdoc is the path to my PDF document.
目前,文件正在发送,但似乎无效(不显示任何内容).
At the moment, the file is being sent over but it seems invalid (displays nothing).
我是否正确地将我的 PDF 转换为 BASE64 编码数据?
Am I correctly converting my PDF to BASE64 encoded data?
谢谢
推荐答案
base64_encode 接受字符串输入.所以你所做的就是对路径进行编码.你应该抓取文件的内容
base64_encode takes a string input. So all you're doing is encoding the path. You should grab the contents of the file
$b64Doc = chunk_split(base64_encode(file_get_contents($this->pdfdoc)));
这篇关于PHP base64编码pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP base64编码pdf文件
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
