mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-08 14:54:30 -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
|
||||
header("Content-Type: multipart/form-data");
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
//header("Access-Control-Allow-Methods: POST");
|
||||
|
||||
//define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
|
||||
require_once PD . "/Model/ImageModel.php";
|
||||
|
||||
/**
|
||||
|
@ -77,6 +75,15 @@ class ImageController extends BaseController {
|
|||
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->imageModel->fileName = $this->imagePayload['name'];
|
||||
|
@ -92,18 +99,18 @@ class ImageController extends BaseController {
|
|||
if (! $this->validateImage()) {
|
||||
return $this->unprocessableEntityResponse();
|
||||
}
|
||||
|
||||
|
||||
if (! $this->handleImage()) {
|
||||
return $this->notFoundResponse();
|
||||
}
|
||||
|
||||
$response = $this->imageModel->insertImage();
|
||||
|
||||
$this->imageModel->insertImage();
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function handleImage() {
|
||||
$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;
|
||||
}
|
||||
return $moved;
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
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');
|
||||
|
||||
// include main configuration file
|
||||
require_once PROJECT_ROOT_PATH . "/include/config.php";
|
||||
|
||||
// include the base controller file
|
||||
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
|
||||
//require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
|
|
@ -19,6 +19,9 @@ require_once PD . "/Model/ModelTraits.php";
|
|||
class ImageModel extends Database {
|
||||
use ModelTraits;
|
||||
|
||||
public $memberId;
|
||||
public $imageBlob;
|
||||
|
||||
public $uploadTo;
|
||||
public $allowFileType;
|
||||
public $fileName;
|
||||
|
@ -28,7 +31,8 @@ class ImageModel extends Database {
|
|||
public $fileType;
|
||||
|
||||
function __construct() {
|
||||
$this->uploadTo = PD . "/public/images/";
|
||||
$this->uploadTo = PD . "\\public\\images\\";
|
||||
//$this->uploadTo = PD . '/public/images/';
|
||||
$this->allowFileType = array('jpg','png','jpeg','gif');
|
||||
}
|
||||
|
||||
|
@ -36,12 +40,12 @@ class ImageModel extends Database {
|
|||
public function insertImage()
|
||||
{
|
||||
//$sql = "INSERT INTO ImageStore(ImageId,Image) VALUES('$this->image_id','" . mysql_escape_string(file_get_contents($tmp_image)) . "')";
|
||||
|
||||
//$fp=addslashes(file_get_contents($_FILES['image']['tmp_name'])); //will store the image to fp
|
||||
//$query = "CALL insert_loyalty_member_image_proc('{$fileName}','{$fp}');";
|
||||
|
||||
$query .= "CALL insert_loyalty_member_image_proc (" . $inputModel[$keys[0]] . ", ";
|
||||
for($i = 0; $i < $n-1; $i++) {
|
||||
$query .= "'" . $inputModel[$keys[$i]] . "', ";
|
||||
}
|
||||
$query .= $inputModel[$keys[$i]] . ")";
|
||||
$query .= "CALL insert_loyalty_member_image_proc (" . $this->memberId . ", " . $this->imageBlob . ")";
|
||||
|
||||
//return var_dump($query);
|
||||
|
||||
$rowCount = $this->processImage($query);
|
||||
|
|
Loading…
Reference in New Issue
Block a user