public function actionCreateTest() { // echo Yii::app()->basePath; // echo '<br>'; // echo Yii::app()->getBaseUrl();die; $model = new FaceImageMaster(); if (isset($_FILES) && !empty($_FILES) && isset($_POST['FaceImageMaster'])) { $model->attributes = $_POST['FaceImageMaster']; $errors = array(); $transaction = Yii::app()->db->beginTransaction(); try { // App::pr($_FILES); $path = 'images/test/'; $allfiles = App::ImageUpload($_FILES["files"], $path); App::pr($allfiles, 2); foreach ($allfiles as $each => $file) { $model->image = $file; if ($model->save()) { echo 'saved'; } } ## follow steps as per requirement in your model $transaction->commit(); } catch (Exception $e) { echo 'data not saved'; $transaction->rollback(); } } $this->render('testform1', array('model' => $model)); }
* if $status =0 then user added with not images added and some problems with image * */ $stauts = 2; if (!empty($image) && $image[0] !== "") { foreach ($image as $i) { $FaceImageMaster = new FaceImageMaster(); $FaceImageMaster->fm_id = $FaceMasterprimarykey; $FaceImageMaster->tracer_id = $tracer_id; $FaceImageMaster->image = $i; $FaceImageMaster->created_on = date('Y-m-d H:i:s'); // print_r($FaceImageMaster);die; if ($FaceImageMaster->save()) { $status = 1; } else { // print_r($FaceImageMaster->getErrors()); $status = 0; } } // print_r($status);die; if ($status == 1) { $response = array("status" => '1', "message" => "User Added."); echo json_encode(array("response" => $response)); die; } else { if ($status == 0) { $response = array("status" => '3', "message" => "User added but image have problem."); echo json_encode(array("response" => $response)); die; } } } else { $response = array("status" => '2', "message" => "User is added but no images are added."); echo json_encode(array("response" => $response)); die; } } else { // echo "<pre>"; // print_r($FaceMaster->getErrors());die; $response = array("status" => '-1', "message" => "error in saving user."); echo json_encode(array("response" => $response)); die; } } } /* * insert aimages * it using multi part * it will replace the InsertRecord function * parameters and output are as it is * */ public function actionInsertRecord() { $post = $_POST; $require = array('user_name', 'tracer_id', 'result'); $error = 0; $msg = array(); foreach ($post as $key => $val) { if (in_array($key, $require)) { if ($post[$key] == '') { $error++; $msg[] = "{$key} is required!"; } } } if ($error > 0) { /* * if empty require field * member_id * lat * lng */ $response = array("status" => '-2', "message" => $msg); echo json_encode(array("response" => $response)); die; } else { $face_master_table = "face_master"; $user_name = $post['user_name']; $tracer_id = $post['tracer_id']; $post['created_on'] = date('Y-m-d H:i:s'); $result = $post['result']; $response_addface = Yii::app()->JsonWebservice->addData($face_master_table, $post, $nfield = "", $uniqueField = "", $lastIdStatus = 0, $fieldEncode = " ", $dataobj = 'db'); // print_r($response_addface['status']==1);die; // print_r($post); // $FaceMaster = new FaceMaster(); // $FaceMaster->user_name = $user_name; // $FaceMaster->tracer_id = $tracer_id; // $FaceMaster->result = $result; // $FaceMaster->created_on = date('Y-m-d H:i:s'); // print_r($FaceMaster);die; if ($response_addface['status'] == 1) { /* * get the new inserted records PK */ // $FaceMasterprimarykey = $FaceMaster->getPrimaryKey(); $FaceMasterprimarykey = $response_addface['lastid']; /* * for giving proper response set flag $status=2 * if $status =1 then user added with images