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: 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 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.


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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥50 LineageOs-21.0系统编译问题
  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力