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)));
相关文章