dongyaoxiu6244 2017-10-27 06:42
浏览 958
已采纳

PHP - 从链接下载pdf文件并保存在本地文件夹中

I am trying to get through an API, a live open access pdf file, and then download that file to my server. However the PDF file does not end with a ".pdf" extension but is encapsulated in a more complexe url: http://aip.scitation.org/doi/pdf/10.1063/1.4996175 A web browser would simply ask to open or save it as a PDF file, whereas my script cannot translate it as such. How can I make my PHP script recognize this url as a PDF file? Thanks in advance. Olivier

  • 写回答

3条回答 默认 最新

  • dongping9475 2017-10-27 06:50
    关注

    It is not clear what exactly you are doing and why your php script has to recognize pdf.

    If you are loading the file by your php application - you can check content type header of the file, which contains file type information along with the extension. You can use http://php.net/manual/en/book.curl.php library for it.

    If you want to let users download the file on your site - you have to set correct content type like this:

    header('Content-Type: application/pdf');
    

    Now the browser will know that the file you are serving is pdf even without extension.

    Update

    Eventually it turned out that the site with pdf files just required some cookies, as described below.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵