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文件


基础教程推荐
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的PDF导出 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01