mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 05:04:29 -06:00
Continued work on image upload
This commit is contained in:
parent
79ad9030bc
commit
16baa575b1
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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]] . "', ";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user