如何用base64格式编码pdf文件?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用base64格式编码pdf文件?相关的知识,希望对你有一定的参考价值。
我这样做了。这是对的吗?
$filename = "../pdfs/reactjs_tutorial.pdf";
$handle = fopen($filename, 'rb');
$contents = fread($handle,filesize($filename));
fclose($handle);
$encoded = chunk_split(base64_encode($contents));
/*This is how I have done*/
答案
$query1 = mysqli_query($con, "SELECT `offer_id` , `offer_img_url` , `terms` FROM `offers` LEFT JOIN system ON system.shop_id = offers.shop_id LEFT JOIN bill ON bill.sys_id = system.sys_id WHERE yb_id = '$yb_id' LIMIT 0 , 30 ");
if(mysqli_affected_rows($con)>0)
{
$data4 = array();
while ($row = mysqli_fetch_array($query1))
{
$data4['offer_id'] = $row['offer_id'];
$data4['offer_img_url'] = base64_encode($row['offer_img_url']);
$data4['terms'] = $row['terms'];
$data2[] = $data4;
}
以上是关于如何用base64格式编码pdf文件?的主要内容,如果未能解决你的问题,请参考以下文章
在 Javascript 中将 PDF 转换为 Base64 编码的字符串