diff --git a/Controller/API/ImageController.php b/Controller/API/ImageController.php index e57d78a..82499e3 100644 --- a/Controller/API/ImageController.php +++ b/Controller/API/ImageController.php @@ -63,15 +63,18 @@ class ImageController extends BaseController { } private function uploadImage(){ + header("Access-Control-Allow-Origin: *"); + header("Access-Control-Allow-Methods: POST"); + header("Content-Type: application/json"); + if ($this->checkRequestType('POST') == 'false') { $this->strErrorDesc = 'Request Method not supported for processAction'; $this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request'; return; } // reads the raw POST data and returns it as a string. - $jsonPayload = file_get_contents('php://input'); - $input = json_decode($jsonPayload, TRUE); - if (! $this->validatePerson($input)) { + $imagePayload = file_get_contents($_FILES['your_image_name']['tmp_name']); + if (! $this->validateImage($imagePayload)) { return $this->unprocessableEntityResponse(); } @@ -80,10 +83,6 @@ class ImageController extends BaseController { } private function insertImage() { - header("Access-Control-Allow-Origin: *"); - header("Access-Control-Allow-Methods: POST"); - header("Content-Type: application/json"); - if (isset($_FILES['image'])) { $uploadImage = $this->processImage(); $success = false; @@ -130,4 +129,15 @@ class ImageController extends BaseController { ]; return $imageInfo; } + + private function validateImage($imageData){ + $validtion = false; + if($imageData['customer_name_first'] != null){ + $validtion = true; + if($imageData['customer_name_last'] == null) { + $validtion = false; + } + } + return $validtion; + } } diff --git a/Model/Database.php b/Model/Database.php index 2f262fe..168aa9d 100644 --- a/Model/Database.php +++ b/Model/Database.php @@ -41,7 +41,7 @@ class Database { return false; } - private function executeQuery($query = "" , $params = []) + /*private function executeQuery($query = "" , $params = []) { try { $stmt = $this->connection->prepare( $query ); @@ -56,7 +56,7 @@ class Database { } catch(Exception $e) { throw New Exception( $e->getMessage()); } - } + }*/ public function processStatement($query = "") { @@ -87,14 +87,14 @@ class Database { return false; } - public function processImage($query = "" , $params = []) { + public function processImage($query = "") { try { $stmt = $this->connection->prepare($query); if($stmt === false) { throw New Exception("Unable to prepare the statement: " . $query); } - $stmt->bind_param("ss", $params['filename'], $params['filepath']); + //$stmt->bind_param("ss", $params['filename'], $params['filepath']); $result = $stmt->execute(); if($result === false) { diff --git a/Model/ImageModel.php b/Model/ImageModel.php index a20baba..66b0432 100644 --- a/Model/ImageModel.php +++ b/Model/ImageModel.php @@ -15,24 +15,14 @@ class ImageModel extends Database { public function insertImage($inputModel) { - // table name for admin profiles - $query = "INSERT INTO " . $this->imageTable; - $query .= " (filename, filepath) VALUES (?,?)"; - - } - - $data = [ - 'Errormsg' => $uploadImage['msg'] ?? '', - 'success' => $success - ]; - - return json_encode($data); + //$query = "INSERT INTO " . $this->imageTable; + //$query .= " (filename, filepath) VALUES (?,?)"; //return var_dump($jsonPayLoad); $keys = array_keys($inputModel); $n = count($keys); - $query .= "CALL insert_new_customer_proc ("; + $query .= "CALL insert_customer_image_proc ("; for($i = 0; $i < $n-1; $i++) { $query .= "'" . $inputModel[$keys[$i]] . "', "; }