【问题标题】:Uploading photo using Appcelerator Cloud Using PHP使用 Appcelerator Cloud 上传照片 使用 PHP
【发布时间】:2013-10-28 09:39:09
【问题描述】:

我正在尝试请求 Appcelerator Cloud 使用照片创建用户,但创建的用户没有照片,但是当我使用请求附加照片时出现此错误 此代码给我错误 "{ "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;
                ?>

【问题讨论】:

    标签: javascript php html appcelerator


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 2010-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多