Continued work on image upload

This commit is contained in:
sctn4elk 2024-05-10 21:37:50 -05:00
parent 79ad9030bc
commit 16baa575b1
3 changed files with 24 additions and 24 deletions

View File

@ -63,15 +63,18 @@ class ImageController extends BaseController {
} }
private function uploadImage(){ private function uploadImage(){
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json");
if ($this->checkRequestType('POST') == 'false') { if ($this->checkRequestType('POST') == 'false') {
$this->strErrorDesc = 'Request Method not supported for processAction'; $this->strErrorDesc = 'Request Method not supported for processAction';
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request'; $this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request';
return; return;
} }
// reads the raw POST data and returns it as a string. // reads the raw POST data and returns it as a string.
$jsonPayload = file_get_contents('php://input'); $imagePayload = file_get_contents($_FILES['your_image_name']['tmp_name']);
$input = json_decode($jsonPayload, TRUE); if (! $this->validateImage($imagePayload)) {
if (! $this->validatePerson($input)) {
return $this->unprocessableEntityResponse(); return $this->unprocessableEntityResponse();
} }
@ -80,10 +83,6 @@ class ImageController extends BaseController {
} }
private function insertImage() { private function insertImage() {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json");
if (isset($_FILES['image'])) { if (isset($_FILES['image'])) {
$uploadImage = $this->processImage(); $uploadImage = $this->processImage();
$success = false; $success = false;
@ -130,4 +129,15 @@ class ImageController extends BaseController {
]; ];
return $imageInfo; 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;
}
} }

View File

@ -41,7 +41,7 @@ class Database {
return false; return false;
} }
private function executeQuery($query = "" , $params = []) /*private function executeQuery($query = "" , $params = [])
{ {
try { try {
$stmt = $this->connection->prepare( $query ); $stmt = $this->connection->prepare( $query );
@ -56,7 +56,7 @@ class Database {
} catch(Exception $e) { } catch(Exception $e) {
throw New Exception( $e->getMessage()); throw New Exception( $e->getMessage());
} }
} }*/
public function processStatement($query = "") public function processStatement($query = "")
{ {
@ -87,14 +87,14 @@ class Database {
return false; return false;
} }
public function processImage($query = "" , $params = []) { public function processImage($query = "") {
try { try {
$stmt = $this->connection->prepare($query); $stmt = $this->connection->prepare($query);
if($stmt === false) { if($stmt === false) {
throw New Exception("Unable to prepare the statement: " . $query); 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(); $result = $stmt->execute();
if($result === false) { if($result === false) {

View File

@ -15,24 +15,14 @@ class ImageModel extends Database {
public function insertImage($inputModel) public function insertImage($inputModel)
{ {
// table name for admin profiles //$query = "INSERT INTO " . $this->imageTable;
$query = "INSERT INTO " . $this->imageTable; //$query .= " (filename, filepath) VALUES (?,?)";
$query .= " (filename, filepath) VALUES (?,?)";
}
$data = [
'Errormsg' => $uploadImage['msg'] ?? '',
'success' => $success
];
return json_encode($data);
//return var_dump($jsonPayLoad); //return var_dump($jsonPayLoad);
$keys = array_keys($inputModel); $keys = array_keys($inputModel);
$n = count($keys); $n = count($keys);
$query .= "CALL insert_new_customer_proc ("; $query .= "CALL insert_customer_image_proc (";
for($i = 0; $i < $n-1; $i++) { for($i = 0; $i < $n-1; $i++) {
$query .= "'" . $inputModel[$keys[$i]] . "', "; $query .= "'" . $inputModel[$keys[$i]] . "', ";
} }