PHP Download Image Or File from URL

Source: Internet
Author: User
Tags php download
I'll show you 3 functions this download a particular file (EX:IMAGE,VIDEO,ZIP,PDF,DOC,XLS,ETC) from a remote resource (vi A valid URL) then save to your server.

Depending on your current php.ini settings, some functions; Therefore, let-try which function is best for you.

Note:please ensure the folder you want to store the downloaded file is existed and have write permission for everyone or T He web process.

For all examples below, I assume this 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/

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.