dqwolwst50489 2013-09-17 08:39
浏览 32
已采纳

如何发送php http请求并检索pdf? [关闭]

I'm beginner with PHP, I would like to download a pdf file from an Indy server.

I'm using a http_get to send the request but It seems wrong since all content type that can be returned is text/html.

So my question is quiet simple: which request should I use to retrieve my pdf file??

After retrieving it, I wish to transfert it.But its maybe an other problem.

  • 写回答

1条回答 默认 最新

  • dsbruqxgt820011351 2013-09-17 09:09
    关注

    You can use the cUrl library or simply use file_get_contents. file_get_contents return FALSE if the file is not there or whatever and it returns the file contents on SUCCESS. You need to capture the contents of the file and save them locally or output them to the browser.

    $content = file_get_contents('file.pdf', fopen('https://url.to/file.pdf', 'r'));
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename=filename.pdf');
    echo $content;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?