小编Kub*_*uba的帖子

PHP + PDF,如何使用curl保存下载的PDF?

欢迎

将下载的pdf保存在页面上有一点问题.要下载pdf,我使用Curl:

$CurlConnect = curl_init();
curl_setopt($CurlConnect, CURLOPT_URL, 'http://website.com/invoices/download/1');
curl_setopt($CurlConnect, CURLOPT_POST,   1);
curl_setopt($CurlConnect, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($CurlConnect, CURLOPT_POSTFIELDS, $request);
curl_setopt($CurlConnect, CURLOPT_USERPWD, $login.':'.$password);
$Result = curl_exec($CurlConnect);
Run Code Online (Sandbox Code Playgroud)

现在在$ Result(字符串)中我拥有所有PDF文件内容.现在开始我的问题.我想保存下载的pdf:

header('Cache-Control: public'); 
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="new.pdf"');
header('Content-Length: '.filesize($Result));
readfile($Result);
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我保存或打开一个新的PDF文件时,我得到一个空白文档.也许问题出在最后几行:

header('Content-Length: '.filesize($Result));
readfile($Result);
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不知道要改变它们以使其发挥作用...我请求你的帮助.谢谢

php pdf curl header save

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

curl ×1

header ×1

pdf ×1

php ×1

save ×1