Complete image upload work on storing image to database

This commit is contained in:
sctn4elk 2024-05-15 14:54:33 -05:00
parent cf1fb1bc63
commit b877d2aaea
8 changed files with 23 additions and 36 deletions

View File

@ -1,12 +1,11 @@
<?php
header("Content-Type: application/json");
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
require_once PD . "/Model/CustomerModel.php";
/**
* Description of CustomerController
*
* @author SCTN4
* @author Mike Howard
* http://localhost:8000/index.php/customer/process/insert?name=Mike%20Howard&email=sctn4elk@msn.com&phone=208-841-4159&birthday=05/07/1965&loyalty=1&city=Winnsboro&state=TX&zip=75494
* http://localhost:8000/index.php/customer/process/select?limit=20
*/
@ -28,7 +27,7 @@ class CustomerController extends BaseController {
try {
$this->requestMethod = $this->getServerRequestMethod();
//return var_dump($this->requestMethod);
switch($this->action) {
case "select":
$response = $this->selectAction();
@ -80,7 +79,6 @@ class CustomerController extends BaseController {
}
$this->customerModel = new CustomerModel();
//return var_dump($this->customerModel);
$this->arrQueryStringParams = $this->getQueryStringParams();
if (isset($this->arrQueryStringParams['customer_id'])) {

View File

@ -1,15 +1,15 @@
<?php
header("Content-Type: application/json");
header("Content-Type: multipart/form-data");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
//header("Access-Control-Allow-Methods: POST");
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
//define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
require_once PD . "/Model/ImageModel.php";
/**
* Description of ImageController
*
* @author SCTN4
* @author Mike Howard
*/
class ImageController extends BaseController {
@ -77,13 +77,14 @@ class ImageController extends BaseController {
return $this->unprocessableRequestResponse();
}
$this->imagePayload = file_get_contents($_FILES['image']['tmp_name']);
$this->imageModel->fileName = $_FILES['image']['name'];
$this->imagePayload = $_FILES['image'];
$this->imageModel->fileName = $this->imagePayload['name'];
if(empty($this->imageModel->fileName)){
return $this->notFoundResponse();
}
$this->imageModel->tempPath = $_FILES["image"]["tmp_name"];
$this->imageModel->tempPath = $this->imagePayload['tmp_name'];
$this->imageModel->basename = basename($this->imageModel->fileName);
$this->imageModel->originalPath = $this->imageModel->uploadTo.$this->imageModel->basename;
$this->imageModel->fileType = pathinfo($this->imageModel->originalPath, PATHINFO_EXTENSION);
@ -102,7 +103,7 @@ class ImageController extends BaseController {
private function handleImage() {
$moved = false;
if(!move_uploaded_file($this->imageModel->tempPath, $this->imageModel->originalPath)) {
if(!move_uploaded_file($_FILES['image']['tmp_name'], $this->imageModel->uploadTo . $this->imageModel->fileName)) {
$moved = true;
}
return $moved;

View File

@ -6,6 +6,7 @@
*/
define("PROJECT_ROOT_PATH", __DIR__ . "/../");
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
// include main configuration file
require_once PROJECT_ROOT_PATH . "/include/config.php";
// include the base controller file

View File

@ -1,4 +1,9 @@
<?php
//define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
//require_once PROJECT_ROOT_PATH . "/Model/Database.php";
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
/**
* Description of CustomerModel
*
@ -22,11 +27,6 @@
* address_zip varchar(10)
*/
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
//require_once PROJECT_ROOT_PATH . "/Model/Database.php";
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
class CustomerModel extends Database {
use ModelTraits;

View File

@ -46,7 +46,6 @@ class Database {
{
try {
//Prepare the statement
//$stmt = $this->connection->stmt_init();
$stmt = $this->connection->prepare($query);
if($stmt === false) {
throw New Exception("Unable to prepare the statement: " . $query);

View File

@ -1,4 +1,6 @@
<?php
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
/**
* Description of ImageModel
@ -14,10 +16,6 @@
* loyalty_value_blob blob
*/
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
class ImageModel extends Database {
use ModelTraits;
@ -30,17 +28,13 @@ class ImageModel extends Database {
public $fileType;
function __construct() {
$this->uploadTo = "public/images/";
$this->uploadTo = PD . "/public/images/";
$this->allowFileType = array('jpg','png','jpeg','gif');
}
/* Process the uploaded image and store in database */
public function insertImage()
{
//return var_dump($jsonPayLoad);
$keys = array_keys($inputModel);
$n = count($keys);
//$sql = "INSERT INTO ImageStore(ImageId,Image) VALUES('$this->image_id','" . mysql_escape_string(file_get_contents($tmp_image)) . "')";
$query .= "CALL insert_loyalty_member_image_proc (" . $inputModel[$keys[0]] . ", ";

View File

@ -3,7 +3,7 @@
/**
* Description of ModelTraits
*
* @author SCTN4
* @author Mike Howard
*/
trait ModelTraits {
private $params = array();

View File

@ -1,14 +1,9 @@
<?php
header("Content-Type: application/json");header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHP.php to edit this template
*/
/* USAGE
* https://localhost/index.php/{MODULE_NAME}/{METHOD_NAME}?limit={LIMIT_VALUE}
* http://localhost/index.php/customer/process/list?limit=20
@ -41,7 +36,6 @@ switch($uri[$uri_pos + 1]) {
case "purchase":
header("HTTP/1.1 404 Module Not Defined");
exit();
//require PROJECT_ROOT_PATH . "/Controller/Api/PurchaseController.php";
//$objFeedController = new PurchaseController();
break;