PHP base64编码pdf文件 [英] PHP base64 encode a pdf file

查看:40
本文介绍了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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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