tags:

views:

16

answers:

1

First of all I'm aware of curl_multi_init but it doesn't exactly do what I need, to my knowledge.

Im downloading files behind a login, so

a) Need to login b) Download image(s)

Here is what I currently have

$login_url = 'https://us.test.com/Member/Login';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$login_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'login='.$this->username.'&password='.$this->userpass.'&signin=1&login_referer=none&remember_me=1');
curl_setopt($ch, CURLOPT_FAILONERROR,1);  
curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/test/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/test/cookie.txt');  
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, true);   
curl_exec($ch);

//Grab and Write the image
$image = file_get_contents($image_url); 
$f = fopen($_SERVER['DOCUMENT_ROOT'].'/test/uploads/'.$id.'.jpg', 'w');
fwrite($f, $image);
fclose($f);  


curl_close($ch);

Anything helps, much appreciated.

A: 

I figured it out, just added session ID into cURL. But a quick and dirty way is

$download_str = 'wget -O '. $save . $id . '.jpg --cookies=off --header "Cookie: PHPSESSID=' . $session_id . '" ' . $image_url;

shell_exec($download_str);

wes