使用php下载的某些PDF文件会被截断

时间:2018-02-21 19:54:14

标签: php function file pdf

我正在尝试编写一个可以在本地保存多个PDF文件的php函数,有些下载得很好,但其他文件似乎被截断,无法用PDF阅读器进行操作。

实际的保存功能由定位路径的函数调用:

   function findURLs(){

      // do something to find URLs & next print them

      while(*some condition*){
         savePDF($url,$id);
      }    
    } 

这是实际功能:

  function savePDF($url,$id){

    $path="../downloads/".$id.".pdf";

    try {
        $data = file_get_contents($url);
        $handle = fopen($path, "w");
        fwrite($handle, $data);
        fclose($handle);
        return true;
        echo "file saved";  
      } catch (Exception $e) {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
      }
      return false;
  }

有什么建议吗?它可能是远程文件大小?

谢谢!

  

* P.S。我希望将文件保存到服务器(我的localhost),而不是通过浏览器下载文件..

0 个答案:

没有答案