Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP从base64编码的数据字符串获取pdf文件_Php_Pdf_Header_Base64_Encode - Fatal编程技术网

PHP从base64编码的数据字符串获取pdf文件

PHP从base64编码的数据字符串获取pdf文件,php,pdf,header,base64,encode,Php,Pdf,Header,Base64,Encode,我有一个base64编码的字符串,其中包含一个pdf。如何使用php从这个编码字符串创建.pdf文件 类似于头函数中的内容类型:application/pdf 试试这段代码 $pdf_base64 = "base64pdf.txt"; //Get File content from txt file $pdf_base64_handler = fopen($pdf_base64,'r'); $pdf_content = fread ($pdf_base64_handler,filesize($p

我有一个base64编码的字符串,其中包含一个pdf。如何使用php从这个编码字符串创建
.pdf
文件

类似于头函数中的
内容类型:application/pdf

试试这段代码

$pdf_base64 = "base64pdf.txt";
//Get File content from txt file
$pdf_base64_handler = fopen($pdf_base64,'r');
$pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64));
fclose ($pdf_base64_handler);
//Decode pdf content
$pdf_decoded = base64_decode ($pdf_content);
//Write data back to pdf file
$pdf = fopen ('test.pdf','w');
fwrite ($pdf,$pdf_decoded);
//close output file
fclose ($pdf);
echo 'Done';

使用此选项,您可以创建并打开文件。。。但也许这不是问题的答案

$data = base64_decode($this->Get(self::Body));
file_put_contents('file.pdf',$data);
答案是用标题回显内容:

$data = base64_decode($this->Get(self::Body));
header('Content-Type: application/pdf');
echo $data;

谢谢萨米,这就是我想要的……干杯……)但是我对我的问题投了-ve票!我的问题中有什么错误吗?对于DomPdf,我只需要
$pdf\u decoded=$DomPdf->output()
//将数据写回pdf文件
中的行。(可能涉及的人)可能的副本