PHP Download Remote File from URL using CURL

Today, We want to share with you PHP Download Remote File from URL using CURL.In this post we will show you PHP download file from url using curl example, hear for php curl save file from url we will give you demo and example for implement.In this post, we will learn about Download A Remote File With Php with an example.

PHP Download Remote File from URL using CURL

There are the Following The simple About PHP Download Remote File from URL using CURL Full Information With Example and source code.

As I will cover this Post with live Working example to develop php curl download file from url, so the php curl download file to browser for this example is following below.

Way 1: Download a remote file using Curl

<?php
 $url  = 'http://www.pakainfo.com/product_catalog.zip';// address of remote file
 $upload_path = '/uploads/filename.zip'; //address of local file
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $con = curl_exec($ch);
 curl_close($ch);
 file_put_contents($upload_path, $con);
?>

used to CURLOPT_RETURNTRANSFER

Download large file using curl

<?php
    $url  = 'http://www.pakainfo.com/product_catalog.zip';//Live Path address of remote file
    $upload_path = '/uploads/product_catalog.zip';//here seimpl upload_path of local file
    $fp = fopen($upload_path, 'w');
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    $data = curl_exec($ch);
    curl_close($ch);
    fclose($fp);
?>

Way 2 : Using file_get_contents()

<?php
$url="hhtp://pakainfo.com/product_catalog.zip";//remote url to download
$upload_path="uploads/product_catalog.zip";//PHP Your local file upload_path
$con=file_get_contents($url);
file_put_contents($upload_path, $con);
?>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Download Remote File from URL using CURL.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Difference between two dates in years, months, days in PHP
  2.   PHP Download Images From URL Using cURL Example
  3.   Download File from URL Using PHP
  4.   Get all eloquent query log using Laravel 7/6 example
  5.   PHP cURL HTTP Request (GET & POST)
  6.   PHP Create zip archive and Download Zip File using ZipArchive
  7.   How to Send Emails Using PHP Scripts
  8.   PHP Parse URL Querystring Into Array
  9.   Download Remote File via PHP CURL
  10.   How to Get Codeigniter last inserted ID from database