我正在尝试请求Appcelerator Cloud创建带照片的用户,用户正在创建没有照片,但是当我将照片附加到请求时我得到此错误 此代码给我错误“{”meta“:{”status“:”fail“,”code“:400,”message“:”无法上传照片:无法识别照片文件“}}”
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;
?>
答案 0 :(得分:1)
您需要以这样的方式发送数据:
$post = array('photo' => '@YOURIMAGENAME',
'email'=>$_POST['email'],
'first_name'=>$_POST['fname'],
'last_name'=>$_POST['lame'],
'password'=>'ciosummit',
'password_confirmation'=>'ciosummit',
'custom_fields'=>$data
);
然后发送curl值,如:
curl_setopt($ch1, CURLOPT_POSTFIELDS,$post);