I am trying to request the Appcelerator Cloud for creating the user with photo, the user is getting created without photo , but when i attach the photo with request i get this error This Code Gives me error "{ "meta": { "status": "fail", "code": 400, "message": "Failed to upload photo: Failed to indentify photo file" } }"
Please Help me with this , i m new to PHP
<?php
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
$data = json_encode(array(
'securitycode' => $_POST['code'],
'designation' => $_POST['desi'],
'comapanyname' => $_POST['cname'],
'companylogoid' => $_POST['clogoid'],
'companyurl' => $_POST['curl'],
'location' => $_POST['location'],
'emailprivateflag' => $_POST['emailp'],
'linkedinurl' => $_POST['linkedin'],
'twitterhandle' => $_POST['twitter'],
'isspeaker' => $_POST['isspeaker'],
'allowaccess' => $_POST['access']
));
//$photo = array('photo' => '@' . $_FILES['file']['name'][0]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.cloud.appcelerator.com/v1/users/login.json?key=LJOVi9A95Y3r6TqlFmxS314v6ox4xaPf");
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie1.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie1.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"login=test@test.com&password=test");
// $html=curl_exec($ch);
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,"https://api.cloud.appcelerator.com/v1/users/create.json?key=LJOVi9A95Y3r6TqlFmxS314v6ox4xaPf");
curl_setopt($ch1, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch1, CURLOPT_HTTPHEADER, Array('Content-Type: multipart/form-data',"Accept: */*"));
// curl_setopt($ch1, CURLOPT_COOKIEFILE,'cookie2.txt');
// curl_setopt($ch1, CURLOPT_COOKIEJAR, 'cookie2.txt');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch1, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, 'email='.$_POST['email'].'&first_name='.$_POST['fname'].'&last_name='.$_POST['lname'].'&password=ciosummit&password_confirmation=ciosummit&photo=@'. $_FILES['file']['tmp_name'][0].'&custom_fields='.$data);
$html=curl_exec($ch1);
header('Location:index.php?status='. rawurlencode($html));
//echo $html;
?>
You need to send the data in an array just like this:
$post = array('photo' => '@YOURIMAGENAME',
'email'=>$_POST['email'],
'first_name'=>$_POST['fname'],
'last_name'=>$_POST['lame'],
'password'=>'ciosummit',
'password_confirmation'=>'ciosummit',
'custom_fields'=>$data
);
And then send the curl values like:
curl_setopt($ch1, CURLOPT_POSTFIELDS,$post);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.