Can somebody please advice why the PDF is not downloading? Always it shows as network error when I hit download. The PDF file is 95 MB size, is that a reason for the network error? I am viwing the file using file_get_contents()
.
Asked
Active
Viewed 121 times
0

VishnuPrasad
- 1,078
- 5
- 17
- 36
-
I think you have an error message in your log like : "Max allocation memory" make a file_get_contents in file of size like yours it's complicate – Inazo Aug 22 '18 at 07:17
1 Answers
0
You can try to use cURL:
// downloads a file and stores it into a file
function getPage($url,$file_ptr)
{
$ch = curl_init();
curl_setopt_array($ch, Array(
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36",
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HEADER => FALSE,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 5,
CURLOPT_URL => $url,
CURLOPT_REFERER => $url,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_FILE => $file_ptr
));
$result = curl_exec($ch);
if(curl_errno ($ch)) $err = curl_error($ch);
else $err = '';
curl_close($ch);
if($err != '') return $err;
return $result;
}
$in_file = tempnam(sys_get_temp_dir(), 'pdf_');
$fp = fopen ($in_file, 'w+');
$ret = getPage($url,$fp);
if($ret === TRUE)
{
fclose($fp);
// do something with the file
}
else
{
fclose($fp);
@unlink($in_file);
}

IVO GELOV
- 13,496
- 1
- 17
- 26