欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-10 17:53:07
...
本地测试:
图片的位置:就是在curl的目录下,
E:\Apache24\htdocs\curl\img_8176.jpg
本地环境:
Window x64位
Apache2.4
PHP7.0 :也就是正式版的第一版
无mysql
代码如下:

curl_upload.php
	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 "
";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


运行的结果:





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