php
  • image
  • curl
  • 2016-06-29 8 views 0 likes 
    0

    私はあなたの助けが必要ですmultipart/form-dataと画像をカールでアップロードします。画像をアップロード、curl + multipart/form-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); 
    

    を、私は要求ペイロードがあります。

      ------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-- 
    

    どのように私は画像のソースを取得することができますか? 私はソースを取得しようとしています:$imgSource = file_get_contents($filepath)が、このテキストを送信した後、サーバーはエラー417を返します。 イメージに有効なparamを送信しない場合、サーバーはjsonリクエストにエラーメッセージを返します(これは通常)

    答えて

    0

    解決済みです。 ヘッダーにExpect: 0を送信する必要があります。

    関連する問題