我正在尝试使用php cURL远程将图片上传到IMGCLICK.NET。
我可以登录并获取/保存cookie,但我无法将远程上传发送到imgclick.net
$url = "http://main.imgclick.net/cgi-bin/upload_file.cgi?upload_id=177781809062&js_on=1&utype=reg&upload_type=url";
$data = array(
'sess_id'=> "aaaaaaaaaaaaaaaaaaa",
'upload_type' => 'url',
'srv_htdocs_url' => 'http://main.imgclick.net',
'url_mass' => 'http://upload.wikimedia.org/wikipedia/commons/c/c1/PHP_Logo.png',
'resize' => '0',
'thumb_size' => '300x300',
'to_folder' => '0',
'per_row' => '1',
'file_adult' => '1',
'tos' => '1',
'submit_btn' => ' Upload! ',
);
$headers = array(
'Host: main.imgclick.net',
'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-GB,en;q=0.5',
'Accept-Encoding: gzip, deflate',
'Referer: http://imgclick.net/',
'Cookie: __cfduid=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; _ga=GA1.2.479494208.1429287148; login=aaaaaaaaaaaaaaaaaaa; xfss=aaaaaaaaaaaaaaaaaaaaaaaaaaa; lang=english; _gat=1',
'Connection: keep-alive',
'Content-Type: multipart/form-data; boundary=---------------------------3323168743628',
'Content-Length: 1231',
);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_USERAGENT, $http_agent );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_REFERER, 'http://imgclick.net/' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_POST, 1);
$codeweb = curl_exec ($ch);
curl_close( $ch );
print_r($codeweb );
我在这段代码中使用了Fiddler中的值并且它运行,但是PHP不是。 请告诉我发生了什么事。感谢。
答案 0 :(得分:0)
这是上传网址:
您提交的表单错误。
如果没有javascript,您可能无法获得上传ID。
当您进入“上传”页面时,您必须使用JavaScript来初始化上传请求。
点击上面的“上传”! JavaScript接管并设置POST请求。
当您选择要上传的文件时,会发生上传POST请求。
这是文件上传 POST请求网址:
http://main.imgclick.net/cgi-bin/upload_file.cgi?upload_id=577123813886&js_on=1&utype=reg&upload_type=file
<强>饼干:强>
Cookie: __cfduid=dcf8c69fbd9ebae2b5d7e75a56bfd792d1430683122
lang=english
login=login name
xfss=jsjl59xvxw0t3kme
标题和内容
Content-Type: multipart/form-data; boundary=
Content-Length: 34688
name="upload_type"
form-data; name="sess_id" jsjl59xvxw0t3kme
name="srv_htdocs_url" http://main.imgclick.net
name="file_0"; filename=""
Content-Type: application/octet-stream
name="file_0";
filename="3zyw5t3yqfru21pdt2wnxazq0271085619.2.jpg"
Content-Type: image/jpeg
[contents of the image files go here]