diff --git a/Controller/API/ImageController.php b/Controller/API/ImageController.php index 532b0e7..3347c7d 100644 --- a/Controller/API/ImageController.php +++ b/Controller/API/ImageController.php @@ -1,9 +1,7 @@ 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; diff --git a/Include/bootstrap.php b/Include/bootstrap.php index bcde848..da5021b 100644 --- a/Include/bootstrap.php +++ b/Include/bootstrap.php @@ -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'; diff --git a/Model/ImageModel.php b/Model/ImageModel.php index 6b694fd..1a63fb1 100644 --- a/Model/ImageModel.php +++ b/Model/ImageModel.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);