mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 15:14:29 -06:00
Upload file to server is complete, begin work on storing image to database
This commit is contained in:
parent
60499cfcf0
commit
ff77fa97af
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
header("Content-Type: multipart/form-data");
|
header("Content-Type: multipart/form-data");
|
||||||
header("Access-Control-Allow-Origin: *");
|
header("Access-Control-Allow-Origin: *");
|
||||||
//header("Access-Control-Allow-Methods: POST");
|
|
||||||
|
|
||||||
//define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
|
|
||||||
require_once PD . "/Model/ImageModel.php";
|
require_once PD . "/Model/ImageModel.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +75,15 @@ class ImageController extends BaseController {
|
||||||
return $this->unprocessableRequestResponse();
|
return $this->unprocessableRequestResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reads the raw POST data and returns it as a string.
|
||||||
|
$jsonPayload = file_get_contents('php://input');
|
||||||
|
$input = json_decode($jsonPayload, TRUE);
|
||||||
|
|
||||||
|
//get the member data
|
||||||
|
$this->memberId = $input['CustomerID'];
|
||||||
|
$this->imageBlob = $input['ImageBlob'];
|
||||||
|
|
||||||
|
//get the file data
|
||||||
$this->imagePayload = $_FILES['image'];
|
$this->imagePayload = $_FILES['image'];
|
||||||
|
|
||||||
$this->imageModel->fileName = $this->imagePayload['name'];
|
$this->imageModel->fileName = $this->imagePayload['name'];
|
||||||
|
@ -97,13 +104,13 @@ class ImageController extends BaseController {
|
||||||
return $this->notFoundResponse();
|
return $this->notFoundResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->imageModel->insertImage();
|
$this->imageModel->insertImage();
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleImage() {
|
private function handleImage() {
|
||||||
$moved = false;
|
$moved = false;
|
||||||
if(!move_uploaded_file($_FILES['image']['tmp_name'], $this->imageModel->uploadTo . $this->imageModel->fileName)) {
|
if(move_uploaded_file($this->imageModel->tempPath, $this->imageModel->uploadTo . $this->imageModel->fileName)) {
|
||||||
$moved = true;
|
$moved = true;
|
||||||
}
|
}
|
||||||
return $moved;
|
return $moved;
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define("PROJECT_ROOT_PATH", __DIR__ . "/../");
|
define("PROJECT_ROOT_PATH", __DIR__ . "/../");
|
||||||
define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
|
define('PD', 'D:\Programs\UniformServer\UniServerZ\www\CustomerRewardsRESTAPI');
|
||||||
//define('PD', 'C:\DEV\UniServerZ\www\CustomerRewardsRESTAPI');
|
//define('PD', 'C:\DEV\UniServerZ\www\CustomerRewardsRESTAPI');
|
||||||
|
|
||||||
// include main configuration file
|
// include main configuration file
|
||||||
require_once PROJECT_ROOT_PATH . "/include/config.php";
|
require_once PROJECT_ROOT_PATH . "/include/config.php";
|
||||||
|
|
||||||
// include the base controller file
|
// include the base controller file
|
||||||
require_once PROJECT_ROOT_PATH . "/Controller/Api/BaseController.php";
|
require_once PROJECT_ROOT_PATH . "/Controller/Api/BaseController.php";
|
||||||
// include the use model file
|
|
||||||
//require_once PROJECT_ROOT_PATH . "/Model/CustomerModel.php";
|
|
||||||
//require_once PROJECT_ROOT_PATH . "/Model/ImageModel.php";
|
|
||||||
// include the tests autoloader when in development
|
// include the tests autoloader when in development
|
||||||
//require_once __DIR__ . '/../vendor/autoload.php';
|
//require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
|
@ -19,6 +19,9 @@ require_once PD . "/Model/ModelTraits.php";
|
||||||
class ImageModel extends Database {
|
class ImageModel extends Database {
|
||||||
use ModelTraits;
|
use ModelTraits;
|
||||||
|
|
||||||
|
public $memberId;
|
||||||
|
public $imageBlob;
|
||||||
|
|
||||||
public $uploadTo;
|
public $uploadTo;
|
||||||
public $allowFileType;
|
public $allowFileType;
|
||||||
public $fileName;
|
public $fileName;
|
||||||
|
@ -28,7 +31,8 @@ class ImageModel extends Database {
|
||||||
public $fileType;
|
public $fileType;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->uploadTo = PD . "/public/images/";
|
$this->uploadTo = PD . "\\public\\images\\";
|
||||||
|
//$this->uploadTo = PD . '/public/images/';
|
||||||
$this->allowFileType = array('jpg','png','jpeg','gif');
|
$this->allowFileType = array('jpg','png','jpeg','gif');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +41,11 @@ class ImageModel extends Database {
|
||||||
{
|
{
|
||||||
//$sql = "INSERT INTO ImageStore(ImageId,Image) VALUES('$this->image_id','" . mysql_escape_string(file_get_contents($tmp_image)) . "')";
|
//$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]] . ", ";
|
//$fp=addslashes(file_get_contents($_FILES['image']['tmp_name'])); //will store the image to fp
|
||||||
for($i = 0; $i < $n-1; $i++) {
|
//$query = "CALL insert_loyalty_member_image_proc('{$fileName}','{$fp}');";
|
||||||
$query .= "'" . $inputModel[$keys[$i]] . "', ";
|
|
||||||
}
|
$query .= "CALL insert_loyalty_member_image_proc (" . $this->memberId . ", " . $this->imageBlob . ")";
|
||||||
$query .= $inputModel[$keys[$i]] . ")";
|
|
||||||
//return var_dump($query);
|
//return var_dump($query);
|
||||||
|
|
||||||
$rowCount = $this->processImage($query);
|
$rowCount = $this->processImage($query);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user