简体   繁体   English

CURL和php pdf文件从一台服务器传输到另一台服务器

[英]CURL and php pdf file transfer from one server to another

I am trying to build a pdf file in server B and trying to transfer back the built pdf file in server A. 我正在尝试在服务器B中构建pdf文件,并试图将已构建的pdf文件传输回服务器A。

This is the code I have in server A 这是我在服务器A中的代码

  $tuCurl = curl_init();
  curl_setopt($tuCurl, CURLOPT_URL, "http://www.server_B/test.php");
  curl_setopt($tuCurl, CURLOPT_POST, 1);
  curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $package);
  curl_setopt($tuCurl, CURLOPT_BINARYTRANSFER, 1);
  curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, TRUE);
  $result=  curl_exec($tuCurl);
  curl_close($tuCurl);

I have all the necessary code to build a pdf file in server B(The header is at server B 我具有在服务器B中构建pdf文件的所有必需代码(标头位于服务器B中

 header('Cache-Control: public');
 header('Content-type: application/pdf');
 header('Content-Disposition: attachment; filename='. $filename);
 header('Content-Length: '.strlen($result));
 echo $result;

). )。 The only problem I have now is to download it back at server A. 我现在唯一的问题是将其下载回服务器A。

Any ideas how we can accomplish that without having to print the header at server A? 有什么想法可以实现而不必在服务器A上打印标题吗?

Remove the headers before echoing it. 在回显之前,请删除标题。

Search for the first occurance of \\n\\n and remove everything before that including the double line break. 搜索\\ n \\ n的第一个匹配项,并删除所有匹配项,包括双换行符。

or try adding this to A: 或尝试将其添加到A:

curl_setopt($tuCurl, CURLOPT_HEADER, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM