$imgname = rand(1111, 9999) . '.jpg';
$result = mb_substr($img, 0, 2);
grab_image('www.example.com/images/' . $result . '/' . $img, dirname(__file__) . '/tmp/' . $imgname);
$imgdata = array('file[]' => "@" . dirname(__file__) . '/tmp/' . $imgname . ";type=image/jpeg", );
$url = 'http://www.example.com/ai/upload_image/0?qqfile='.$imgname;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36');
curl_setopt($ch, CURLOPT_COOKIE, "adw_ic=$adw_ic; s=$s; sli=$sli; xtan=$xtan; xtant=$xtant; xtvrn=$xtvrn");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Connection: keep-alive",
"Origin: http://www.example.com",
"Referer: http://www.example.com/nl/ai/form/0",
"Accept:*/*",
"Accept-Encoding: gzip,deflate,sdch",
"Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2,es;q=0.2",
"Content-Type: application/octet-stream",
"X-Requested-With: XMLHttpRequest",
"X-File-Name: ".encodeURIComponent($imgname),
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "@" . dirname(__file__) . '/tmp/' . $imgname . ";type=image/jpeg");
$result = curl_exec_follow($ch);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );
print_r($headerSent);
curl_close($ch);
echo $result;
unlink(dirname(__file__) . '/tmp/' . $imgname);
Desbetreffende js bestand:
En volgens mij is dit het code uit het js bestand welke ik moet reproduceren wat dus niet lukt:
_upload: FUNCTION(ID, params){
var file = this._files[ID],
NAME = this.getName(ID),
SIZE = this.getSize(ID);
this._loaded[ID] = 0;
var xhr = this._xhrs[ID] = new XMLHttpRequest();
var self = this;
xhr.upload.onprogress = FUNCTION(e){
IF (e.lengthComputable){
self._loaded[ID] = e.loaded;
self._options.onProgress(ID, NAME, e.loaded, e.total);
}
};
xhr.onreadystatechange = FUNCTION(){
IF (xhr.readyState == 4){
self._onComplete(ID, xhr);
}
};
// build query STRING
params = params || {};
params['qqfile'] = NAME;
var queryString = qq.obj2url(params, this._options.action);
xhr.OPEN("POST", queryString, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.send(file);
},
Kan iemand mij op weg helpen?