I'm trying to download a biggish csv file from a website. I've seen the suggestion to use file_get_contents and file_put_contents but due to the file size I opted to use cURL and its file handle option so the data goes directly to file rather that into PHP memory.
However I seem to be getting a weird error where by the entire file doesn't always download and I'm unsure how to verify that the entire file has been downloaded without using the response headers which I'm not sure how to access when using the file handle option of cURL.
This is what I am using at the minute to get the file.
$ch = curl_init('*FILE_TO_GET*');
$fp = fopen('*WHERE_TO_FILE*', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
The files is approximately 3.8 MB at the moment however it has the potential to get much larger.