You are here

5 December 2016

This snippet shows you how to download a file from url without loading it to memory. When you use file_get_contents() and file_set_contents() you load the content to memory and then to file. The right way to do that would be to save it in chunks to file. Easier way is to use library called "Guzzle, PHP HTTP client".

Source code viewer
  1. $client = new GuzzleHttp\Client();
  2.  
  3. $client->request(
  4. 'GET',
  5. 'DOWLOAD_URL_DIR',
  6. array('sink' => 'SAVE_FILE_DIR')
  7. );
Programming Language: PHP