Home  >  Article  >  Backend Development  >  curl上传图片,服务器端接受不到图片

curl上传图片,服务器端接受不到图片

WBOY
WBOYOriginal
2016-06-20 12:40:07988browse

本地测试:
图片的位置:就是在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;    }?>
对于服务器端:
upload_server.php
<?php print_r($_POST);echo "\n_______________________\n";print_r($_FILES['pic']);?>


运行的结果:





Array ( [uid] => 10086 [pic] => @E:\Apache24\htdocs\curl\img_8176.jpg;type=image/png )

Array
(
    [uid] => 10086
    [pic] => @E:\Apache24\htdocs\curl\img_8176.jpg;type=image/png
)

_______________________


Notice:  Undefined index: pic in E:\Apache24\htdocs\curl\upload_server.php on line 4

string(239) "Array ( [uid] => 10086 [pic] => @E:\Apache24\htdocs\curl\img_8176.jpg;type=image/png ) _______________________
Notice: Undefined index: pic in E:\Apache24\htdocs\curl\upload_server.php on line 4





回复讨论(解决方案)

问题已经解决了
错误原因以及解决方案见文档
http://segmentfault.com/a/1190000000725185

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn