首先,我知道curl_multi_init,但据我所知,它并不能完全满足我的需要。
我在登录后下载文件,所以
a) 需要登录
b) 下载图像
这是我目前拥有的
$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);
任何帮助,非常感谢。
我想通了,只需将会话 ID 添加到 cURL 中即可。但一个快速而肮脏的方法是
$download_str = 'wget -O '。 $保存。 $id 。 '.jpg --cookies=off --header "Cookie: PHPSESSID=' . $session_id . '" ' . $图像_url;
shell_exec($download_str);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)