Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP CURL多部分表单数据使用上载问题_Php_Form Data_Boundary - Fatal编程技术网

PHP CURL多部分表单数据使用上载问题

PHP CURL多部分表单数据使用上载问题,php,form-data,boundary,Php,Form Data,Boundary,我试图上传图像到Api网站,但网站回答没有上传图像。我测试了所有代码,但没有结果。请帮助我这是我的脚本代码: $BOUNDARY = $this->randomPassword(); $BODY=""; $BODY .= '------WebKitFormBoundary'.$BOUNDARY. $eol; $BODY .= 'Content-Disposition: form-data; na

我试图上传图像到Api网站,但网站回答没有上传图像。我测试了所有代码,但没有结果。请帮助我

这是我的脚本代码:

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



欢迎来到SO。请花点时间阅读和编辑您的问题。谢谢兄弟。节省了我的时间。
        $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;