2016-06-29 14 views
0

Ich brauche deine Hilfe bei multipart/form-data und lade Bilder mit curl hoch.Bild hochladen, curl + multipart/form-data

Ich habe diesen Code zum Erzeugen und Senden von Daten:

 $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); 

und ich habe Anfrage Nutzlast:

  ------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 the souce of the image itself like "ÿØÿàÿØÿàÿØÿàÿØÿàÿØÿàÿØÿà" 
      ------WebKitFormBoundaryibLm7G5cqxCOuAFy 
      Content-Disposition: form-data; name="scrid" 

      32482346-7100587438898460646 
      ------WebKitFormBoundaryibLm7G5cqxCOuAFy-- 

Wie ich Quelle Bild zu bekommen? Ich versuche, Quelle zu erhalten: $imgSource = file_get_contents($filepath), aber nach diesem Text senden Server Fehler 417. Wenn sende kein gültiges Parament für das Image, gibt der Server json-Anfrage mit Fehlermeldungen zurück (dies ist normalerweise)

Antwort

0

Gelöst. Senden Sie Expect: 0 in Kopfzeilen.