当前位置:Gxlcms > PHP教程 > PHPDownloadImageOrFileFromURL

PHPDownloadImageOrFileFromURL

时间:2021-07-01 10:21:17 帮助过:3人阅读

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/

人气教程排行