curl / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Download remote PDF using php code

From: Omar, Nour <eng.nour.omar87_at_gmail.com>
Date: Thu, 3 Aug 2017 10:32:00 +0200

Hello all,

I want to download a pdf file from a server to my local device. I used
the following code:

|$url="https://www.example.com/test.pdf";$file
=fopen(dirname(__FILE__)."/PDF Files/".$filename,'w+');$curl
=curl_init($url);curl_setopt_array($curl,[CURLOPT_URL
=>$url,CURLOPT_BINARYTRANSFER =>1,// No effect from PHP
5.1.3CURLOPT_RETURNTRANSFER =>1,CURLOPT_FILE =>$file,CURLOPT_TIMEOUT
=>50,CURLOPT_USERAGENT =>'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT
5.0)']);$response =curl_exec($curl); |After running the code, I find the PDF file on my local device but when I
  open it, i get a message saying that the file is corrupted.

  Any help?

Best regards
Nour Omar.

**

_______________________________________________
https://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2017-08-03