Skip to main content

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.

Also Read :  Set Cookies Get Cookies Delete Cookies with PHP

Way 1: Download a remote file using Curl

<?php
 $url  = 'https://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  = 'https://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.

Web Developer

Hi, I’m Web developer, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]