CodeIgniter Forums
Download file with curl - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Download file with curl (/showthread.php?tid=58424)



Download file with curl - El Forum - 06-11-2013

[eluser]joe_h[/eluser]
Greetings, I'm trying to download a file with curl Seller codeigniter, but I could not save the contents of the file, the code is as follows:

Code:
$this->curl->create($value->url);

//he jugado con todas estas opciones que estan comentadas y nada
//$this->curl->option('buffersize', 10);
//$this->curl->option('useragent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)');
//$this->curl->option('returntransfer', 1);
//$this->curl->option('followlocation', 1);
//$this->curl->option('connecttimeout', 600);


//por si a traves de la aplicacion quiero utilizar un proxy para descargar el fichero
if ($options[0]->proxy_use == "1") {
$this->curl->proxy($options[0]->proxy, $options[0]->proxy_port);
$this->curl->proxy_login($options[0]->proxy_user, $options[0]->proxy_pass);
}

$carpeta = $value->ext;
$dir = $options[0]->path_to_save . "/" . $carpeta;
if (!is_dir($dir)) {//si no existe la direccion
mkdir($dir);
$fp = fopen($dir . "/" . $value->name . "." . $value->ext, 'w');
$this->curl->option('file', $fp);
$this->curl->option('connecttimeout', 60);
//fwrite($fp, $descarga);
} else {
$fp = fopen($dir . "/" . $value->name . "." . $value->ext, 'w');
$this->curl->option('file', $fp);
$this->curl->option('connecttimeout', 60);
//fwrite($fp, $descarga);
}



$descarga = $this->curl->execute();
$info = $this->curl->info;
$this->curl->debug();
$this->curl->close();
fclose($fp);

The idea is that when the file is supposed to go down there to check if a certain location a folder with the extension of the file and inside that folder to save the file, but I only creates a file with a size 0.

It appears that the content of the doc not this fall.

Why??