php copy saves remote pdf but viewers throw error message


Here is my code:

$file = ‘’;
$newfile = ‘c:\example.pdf’;

if (!copy($file, $newfile)) {
echo “failed to copy $file…\n”;

The file saves just fine. When I try to open it I get an error from the reader (both Adobe and Nitro) that indicates that the file is corrupt. When I go to and either click save target as or open the file in a reader then I can save it and open it later with no problems.

I have also tried cURL with the same results. Here’s the code:

$url = ‘’;
$path = ‘c:\example.pdf’;

$fp = fopen($path, 'w');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);

$data = curl_exec($ch);


Can you help?

Sponsor our Newsletter | Privacy Policy | Terms of Service