php - upload image, curl+multipart/form-data -


i need multipart/form-data , uploading image curl.

i have code generating , sending data:

        $boundary = '----webkitformboundarylzi2dppfuicxxqt0';         $eol = "\r\n";          $postdata = '';         $postdata .= '--'.$boundary.$eol;         $postdata .= 'content-disposition: form-data; name="scrid"'.$eol.$eol;         $postdata .= $scrid.$eol;         $postdata .= '--'.$boundary.$eol;         $postdata .= 'content-disposition: form-data; name="file"; filename="'.$filepath.'"'.$eol;         $postdata .= "content-type: {$imginfo['mime']}".$eol.$eol;         $postdata .= $img.$eol;         $postdata .= '--'.$boundary.'--';          $headers = array(             "content-length: " . strlen($postdata),             "content-type: multipart/form-data;boundary=----webkitformboundarylzi2dppfuicxxqt0",             "x-requested-with: xmlhttprequest",             "origin:http://www.ebayclassifieds.com",             "accept-encoding: gzip, deflate",             "accept:application/json, text/javascript, */*;",         );          curl_setopt($this->_ch, curlopt_url, 'http://www.ebayclassifieds.com/m/imageupload');         curl_setopt($this->_ch, curlopt_httpheader, $headers);         curl_setopt($this->_ch, curlopt_postfields, $postdata);         curl_setopt($this->_ch, curlopt_followlocation, 1);         curl_setopt($this->_ch, curlopt_post, 1);         curl_setopt($this->_ch, curlopt_cookiesession, true);         curl_setopt($this->_ch, curlopt_cookiejar, $this->_cookiefilepath);         curl_setopt($this->_ch, curlopt_cookiefile, $this->_cookiefilepath);         curl_setopt($this->_ch, curlopt_returntransfer, 1);         curl_setopt($this->_ch, curlopt_referer, "http://www.ebayclassifieds.com/m/postad?scrid=$scrid");          $imageform =  curl_exec($this->_ch); 

and have request payload:

          ------webkitformboundaryiblm7g5cqxcouafy           content-disposition: form-data; name="file"; filename="1-g-0-032-   oz-silver-valcambi-bullion-bar-999-rev.jpg"           content-type: image/jpeg            here appears souce of image "ÿØÿàÿØÿàÿØÿàÿØÿàÿØÿàÿØÿà"           ------webkitformboundaryiblm7g5cqxcouafy           content-disposition: form-data; name="scrid"            32482346-7100587438898460646           ------webkitformboundaryiblm7g5cqxcouafy-- 

how can source of image? trying source: $imgsource = file_get_contents($filepath), after send text, server return error 417. if send not valid parament image, server return json request error messages(this in normally)

resolved. need send expect: 0 in headers.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -