Reputation: 51
I am trying to upload image to Api site, but site answer no upload image. I tested all codes but no result. Please help me
Upvotes: 2
Views: 1424
Reputation: 51
This my script code:
$BOUNDARY = $this->randomPassword();
$BODY="";
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowChunkNumber"' . $eol . $eol;
$BODY .= "1" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowChunkSize"' . $eol . $eol;
$BODY .= "15728640" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowCurrentChunkSize"' . $eol . $eol;
$BODY .= "2382085" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowTotalSize"' . $eol . $eol;
$BODY .= "2382085" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowIdentifier"' . $eol . $eol;
$BODY .= "2382085-111jpg" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowFilename"' . $eol . $eol;
$BODY .= "111.jpg" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowRelativePath"' . $eol . $eol;
$BODY .= "111.jpg" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowTotalChunks"' . $eol . $eol;
$BODY .= "1" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="flowTotalChunks"' . $eol . $eol;
$BODY .= "1" . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$BODY .= 'Content-Disposition: form-data; name="file"; filename="111.jpg"'. $eol ;
$BODY .= 'Content-Type: image/jpeg' . $eol . $eol;
//$BODY.= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$BODY .= chunk_split(file_get_contents("111.jpg")) . $eol;
$BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"multipart/form-data; boundary=----WebKitFormBoundary".$BOUNDARY,
'X-AUTH-TOKEN: '.$Token.'',
'X-Requested-With: XMLHttpRequest'
));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/1.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0');
curl_setopt($ch, CURLOPT_URL, "https://sitename.php/api/upload.php?/dealer/starterpack/upload/".$TransID."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_REFERER, "https://sitename.php/starter-starterkit");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $BODY);
$response = curl_exec($ch);
echo $response;
Upvotes: 3