i’ll show you 3 functions that download a particular file (ex: image,video,zip,pdf,doc,xls,etc) from a remote resource (via a valid url) then save to your server.
depending on your current php.ini settings, some functions may not work; therefore, let try which function is best for you.
note: please ensure the folder you want to store the downloaded file is existed and has write permission for everyone or the web process.
for all examples below, i assume that we’re going to download a remote image from: http://4rapiddev.com/wp-includes/images/logo.jpg and save it to a download sub folder with name: file.jpg.
1. php download remote file with file_get_contents and file_put_contents
example:
2. php download remote file with curl
example:
3. php download remote file with fopen
example:
again, “download” folder must be exists and writable.
from: http://4rapiddev.com/php/download-image-or-file-from-url/