post - How do I prevent a redirect after using PHP cURL to upload images to another site? -
a site has form allow uploading 1 image @ time. use php curl upload multiple images zip file, works.
i see curl_exec response , curl_getinfo data in browser after uploads done. however, able see them split second before redirected site images uploaded to:
$ch = curl_init($this->adata['urldata']['actionurl']); foreach ($this->adata['images'] $afile) { $suploadfile = $this->curluploadfilename($afile); $apostdata = array('sfromurl' => $sfromurl, 'token' => $stoken, 'uploadfile' => $suploadfile, 'upload' => 1); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_useragent, $_server['http_user_agent']); curl_setopt($ch, curlopt_referer, $_server['http_referer']); curl_setopt($ch, curlopt_cookie, $scookies); curl_setopt($ch, curlopt_postfields, $apostdata); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlinfo_header_out, true); curl_setopt($ch, curlopt_followlocation, false); $aresponse = curl_exec($ch); if(curl_errno($ch) != 0) { $this->serrormsg = "post curl error:\r\n" . curl_error($ch) . "\r\n"; curl_close($ch); return false; } $atempinfo[] = array('image' => $afile, 'curlinfo' => curl_getinfo($ch), 'curlresponse' => $aresponse); } $this->ainfo = $atempinfo; curl_close($ch); return true;
i have curlopt_followlocation set false , still redirects. not in safe_mode , open_basedir not set.
i have added curlopt_nobody true , curlopt_customrequest post (to keep request switching head). different results:
if added after curlopt_postfields, not redirected uploads fail.
if added before, uploads succeed still redirected.
i know curlopt_header , curlinfo_header_out supposed do, set them both false see if makes difference, still redirected.
i know old post, go ahead , answer it. believe when echo results, there javascript in response doing redirect. try dumping response file instead of in browser , see if there javascript in there, if found remove culprit part of script doing str_replace()
or , echo output.
Comments
Post a Comment