0

我正在尝试请求 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;
                ?>
4

1 回答 1

0

您需要像这样在数组中发送数据:

$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);
于 2013-12-09T22:47:16.577 回答