I'm trying to download a PDF file from a URL with php & curl. It has to return the file into a variable so i can put it in a base64 string.
If i run it, i keep getting a 404 "file not found" from the server (and if i post the url in my browser the file just downloads correctly).
$ch = curl_init();
$request_headers = array(
"Content-Type:application/pdf",
"Content-Disposition:attachment;filename='downloaded.pdf'",
);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$data = curl_exec($ch);
curl_close($ch);