使用php Curl进行多文件上传
我正在尝试使用CurlFile函数上载多个图像。这是我传递给curl函数的数组:使用php Curl进行多文件上传,php,arrays,curl,file-upload,Php,Arrays,Curl,File Upload,我正在尝试使用CurlFile函数上载多个图像。这是我传递给curl函数的数组: array (size=16) 'action' => string 'saveM' (length=12) 'firstName' => string 'qwer' (length=4) 'lastName' => string '' (length=0) 'gender' => string 'male' (length=4) 'dateOfBirth' =>
array (size=16)
'action' => string 'saveM' (length=12)
'firstName' => string 'qwer' (length=4)
'lastName' => string '' (length=0)
'gender' => string 'male' (length=4)
'dateOfBirth' => string '' (length=0)
'dateOfDeath' => string '' (length=0)
'type' => string 'family' (length=6)
'biography' => string 'wqer' (length=4)
'graveLat' => string '' (length=0)
'graveLong' => string '' (length=0)
'communityId' => string '' (length=0)
'members' => string '' (length=0)
'privacy' => string 'public' (length=6)
'token' => string 'a31818ff1f18f1d318fe6' (length=22)
'image' =>
object(CURLFile)[35]
public 'name' => string 'D:\xampp\tmp\phpC6BD.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'head-659652_640.png' (length=19)
'photos' =>
array (size=4)
0 =>
object(CURLFile)[36]
public 'name' => string 'D:\xampp\tmp\phpC6CE.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '2584150-1486688827928-funnyprofile.jpg' (length=38)
1 =>
object(CURLFile)[37]
public 'name' => string 'D:\xampp\tmp\phpC6CF.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '5993755201548256265.jpg' (length=23)
2 =>
object(CURLFile)[38]
public 'name' => string 'D:\xampp\tmp\phpC6D0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'dummy-image1.jpg' (length=16)
3 =>
object(CURLFile)[39]
public 'name' => string 'D:\xampp\tmp\phpC6E0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'head-659652_640.png' (length=19)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => self::$api_url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => ($apicall)
));
$result = curl_exec($curl);
curl_close($curl);
这是旋度函数:
array (size=16)
'action' => string 'saveM' (length=12)
'firstName' => string 'qwer' (length=4)
'lastName' => string '' (length=0)
'gender' => string 'male' (length=4)
'dateOfBirth' => string '' (length=0)
'dateOfDeath' => string '' (length=0)
'type' => string 'family' (length=6)
'biography' => string 'wqer' (length=4)
'graveLat' => string '' (length=0)
'graveLong' => string '' (length=0)
'communityId' => string '' (length=0)
'members' => string '' (length=0)
'privacy' => string 'public' (length=6)
'token' => string 'a31818ff1f18f1d318fe6' (length=22)
'image' =>
object(CURLFile)[35]
public 'name' => string 'D:\xampp\tmp\phpC6BD.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'head-659652_640.png' (length=19)
'photos' =>
array (size=4)
0 =>
object(CURLFile)[36]
public 'name' => string 'D:\xampp\tmp\phpC6CE.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '2584150-1486688827928-funnyprofile.jpg' (length=38)
1 =>
object(CURLFile)[37]
public 'name' => string 'D:\xampp\tmp\phpC6CF.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '5993755201548256265.jpg' (length=23)
2 =>
object(CURLFile)[38]
public 'name' => string 'D:\xampp\tmp\phpC6D0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'dummy-image1.jpg' (length=16)
3 =>
object(CURLFile)[39]
public 'name' => string 'D:\xampp\tmp\phpC6E0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'head-659652_640.png' (length=19)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => self::$api_url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => ($apicall)
));
$result = curl_exec($curl);
curl_close($curl);
图像数组正确上传文件,但我的问题在于照片根本没有上传多个图像,并给出错误“数组到字符串转换”
有什么想法吗?我通过将照片中的内容更改为以下内容来修复它:
'photos[0]' =>
object(CURLFile)[36]
public 'name' => string 'D:\xampp\tmp\phpC6CE.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '2584150-1486688827928-funnyprofile.jpg' (length=38)
'photos[1]' =>
object(CURLFile)[37]
public 'name' => string 'D:\xampp\tmp\phpC6CF.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string '5993755201548256265.jpg' (length=23)
'photos[2]' =>
object(CURLFile)[38]
public 'name' => string 'D:\xampp\tmp\phpC6D0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'dummy-image1.jpg' (length=16)
'photos[3]' =>
object(CURLFile)[39]
public 'name' => string 'D:\xampp\tmp\phpC6E0.tmp' (length=24)
public 'mime' => string '' (length=0)
public 'postname' => string 'head-659652_640.png' (length=19)