Maison > Article > développement back-end > 200分CURL设置HTTPHEADER上传文件有关问题!(补充提问)
200分求助CURL设置HTTPHEADER上传文件问题!(补充提问)
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $boundary = md5(time()); $postStr = ""; $postStr .="--".$boundary."\r\n"; $postStr .="Content-Disposition: form-data; name=\"uptxt[]\"; filename=\"index_1.html\"\r\n"; $postStr .="Content-Type: text/html\r\n\r\n"; $postStr .=$uploadFile."\r\n"; #这里是部分文件内容 $postStr .="--".$boundary."\r\n";
$boundary = md5(time()); $postStr = ""; $postStr .="--".$boundary."\r\n"; $postStr .="Content-Disposition: form-data; name=\"uptxt[]\"; filename=\"index_1.html\""; $postStr .="Content-Type: text~html"; $postStr .="123\r\n"; #这里是部分文件内容 $postStr .="--".$boundary."\r\n"; <br><font color="#e78608">------解决方案--------------------</font><br>不是用curl吗?网上找了一段是这样的:<br>
<?php $url = 'http://www.myheritage.cn/FP/Company/tryFaceRecognition.php';//target url $fields['file'] = '@'.'C:\Users\lzyy\Desktop\3431821560_5e18c02221.jpg'; $fields['lang'] = 'ZH'; $fields['morph'] = '1'; $fields['popup'] = 'PJSLVMMT'; $fields['loadMethod'] = 'myFiles'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields ); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, "http://www.myheritage.cn/"); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);//get redirect content curl_exec( $ch ); //$rs = curl_exec($ch); if ($error = curl_error($ch) ) { die($error); } curl_close($ch); //print_r(htmlspecialchars($rs)); echo 'ok'; ?> <br><font color="#e78608">------解决方案--------------------</font><br>