Jump to content

Download file to server using curl?


siddscool19

Recommended Posts

Something like that? I haven't tried it, but it's supposed to work.

 

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.site.com/pic.jpg');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password')

$data = curl_exec();
curl_close($ch);

?>

 

Orio.

<?php
/*
This is usefull when you are downloading big files, as it
will prevent time out of the script :
*/
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....
$filename=$_POST["filename"];
$file=$_POST["file"];
$fp = fopen (dirname(__FILE__) . '/'.$filename.'', 'w+');//This is the file where we save the information
$ch = curl_init($file);//Here is the file we are downloading
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

 

I am using this coding to download the file... It does downloads the file.. The smaller files are perfectly downloaded but the bigger files like of 100mb it does download but their link doesn't work it shows them as they doesn't exist..........

Any way to fix it?

I believe the problem is with:

 

curl_setopt($ch, CURLOPT_TIMEOUT, 50);

 

You are limiting the amount of time of downloading to 50 seconds. I don't believe you can download 100MB in 50 secs.

If you want it to never timeout, set it to zero (or a very big number at least).

 

Orio

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.