PHP: stream remote pdf to client browser

2019-01-24 14:31发布

there's a pdf generated on an external service and I would like to stream the pdf to the browser in my php server while streaming to client so that I don't need to download the pdf from the remote file and then start initializing download. I would just have the file immediately download or stream to the client requesting it.

标签: php stream
1条回答
姐就是有狂的资本
2楼-- · 2019-01-24 14:56

Assuming that the generated pdf is in http://bar.com/foo.pdf, you could do:

  $data = file_get_contents("http://bar.com/foo.pdf");
  header("Content-type: application/octet-stream");
  header("Content-disposition: attachment;filename=YOURFILE.pdf");

  echo $data;
查看更多
登录 后发表回答