Heim > Artikel > Backend-Entwicklung > curl上传图片,服务器端接受不到图片
本地测试:
图片的位置:就是在curl的目录下,
E:\Apache24\htdocs\curl\img_8176.jpg
本地环境:
Window x64位
Apache2.4
PHP7.0 :也就是正式版的第一版
无mysql
代码如下:
curl_upload.php
<?php $data = array( 'uid' => 10086, 'pic' => "@".realpath('./img_8176.jpg').";type=image/png");print_r($data);$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://192.168.10.103/curl/upload_server.php' );curl_setopt($ch, CURLOPT_POST, true );//curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);//curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);//模拟浏览器动作curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false );curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$return_data= curl_exec($ch);echo "<pre class="brush:php;toolbar:false">";print_r($return_data);echo "";curl_close($ch);var_dump($return_data); if(@curl_errno($return_data)==0){ return json_decode($return_data,true); }else { return false; }?>
<?php print_r($_POST);echo "\n_______________________\n";print_r($_FILES['pic']);?>
问题已经解决了
错误原因以及解决方案见文档
http://segmentfault.com/a/1190000000725185