Reputation: 133
I'm trying to upload multiple images using the CurlFile function. This is the array i'm passing to the curl function:
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)
and this is the curl function:
$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);
The image array uploads the files correctly, however my issue lies with the photos multiple images not uploading at all and give an error "Array to string conversion"
Any ideas?
Upvotes: 2
Views: 1058
Reputation: 133
I managed to fix it by changing the out of the photos to be like this:
'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)
Upvotes: 1