I'm trying to download invoices(loop) to my uploads folder so clients can download. I don't want to redirect. I've tried file get and put contents. Got empty pdfs. then tried curl:
$ch = curl_init($pdfurl);
$fp = fopen('../uploads/'. $invoice. '', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Doesnt seem to work.. the pdfurl is a download link, it doesnt show pdf, it prompts u to download.. that might be the problem?
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="$invoice.pdf"');
// The PDF source is in original.pdf
readfile($pdfurl);
This works. but I want to move the pdfs from loop to upload folder.
...problem solved.. was on development server.. thats why i couldnt open the pdfs..
file_put_contents("../uploads/".$factuurnummer. ".pdf", fopen($pdfurl, 'r'));