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
- $client = new GuzzleHttp\Client();
- array('sink' => 'SAVE_FILE_DIR')
- );Programming Language: PHP