File upload
This commit is contained in:
@@ -6,7 +6,7 @@ use CodeIgniter\Model;
|
|||||||
class UploadManager extends Model
|
class UploadManager extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
public $savePath ="/opt/wrenchboard/TEST/"; ////10.0.0.40/wrenchboard/TEST/";
|
public $savePath ="/opt/wrenchboard/TEST/";
|
||||||
public function reciveUpload($in,$out){
|
public function reciveUpload($in,$out){
|
||||||
|
|
||||||
$action = $in["action"];
|
$action = $in["action"];
|
||||||
@@ -35,7 +35,8 @@ class UploadManager extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($thisContactFolder)) {
|
if (file_exists($thisContactFolder)) {
|
||||||
$out["message"] = rand(100,999)."-".$in['file_name'];
|
$tt_d = date('hisjmy');
|
||||||
|
$out["message"] = $tt_d."-".$in['file_name'];
|
||||||
$thisContactFolderFileName = $thisContactFolder.'/'.$out["message"];
|
$thisContactFolderFileName = $thisContactFolder.'/'.$out["message"];
|
||||||
$myfile = fopen($thisContactFolderFileName, "w") or die("Unable to open file!");
|
$myfile = fopen($thisContactFolderFileName, "w") or die("Unable to open file!");
|
||||||
$file_data = base64_decode($in["file_data"]);
|
$file_data = base64_decode($in["file_data"]);
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function reciveUpload($in,$out){
|
||||||
|
$savePath ="/opt/wrenchboard/TEST/";
|
||||||
|
$action = $in["action"];
|
||||||
|
|
||||||
|
|
||||||
|
//DECIDE IF PARENT FOLDER IS PRESENT
|
||||||
|
if (!file_exists($savePath.'CONTRACTS')) {
|
||||||
|
mkdir($savePath.'CONTRACTS', 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($savePath.'PROFILE')) {
|
||||||
|
mkdir($savePath.'PROFILE', 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($savePath.'JOBS')) {
|
||||||
|
mkdir($savePath.'JOBS', 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($action){
|
||||||
|
|
||||||
|
case WRENCHBOARD_CONTRACT_MESSAGE:
|
||||||
|
// MAKE SURE FOLDER AS PER PROECESS IS AVILABLE
|
||||||
|
$thisContactFolder = $savePath.'CONTRACTS/'.$in["contract"];
|
||||||
|
if (!file_exists($thisContactFolder)) {
|
||||||
|
mkdir($thisContactFolder, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($thisContactFolder)) {
|
||||||
|
$tt_d = date('hisjmy');
|
||||||
|
$out["message"] = $tt_d."-".$in['file_name'];
|
||||||
|
$thisContactFolderFileName = $thisContactFolder.'/'.$out["message"];
|
||||||
|
$myfile = fopen($thisContactFolderFileName, "w") or die("Unable to open file!");
|
||||||
|
$file_data = base64_decode($in["file_data"]);
|
||||||
|
fwrite($myfile, $file_data);
|
||||||
|
fclose($myfile);
|
||||||
|
$out["call_backend"] = true; // flag ready to save data entry
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
include '../../../backend.php';
|
include '../../../backend.php';
|
||||||
include 'constants.php';
|
include 'constants.php';
|
||||||
include 'formarter.php';
|
include 'formarter.php';
|
||||||
|
include 'UploadManager.php';
|
||||||
|
|
||||||
$endpoints = array(
|
$endpoints = array(
|
||||||
'apigate' => array('POST'),
|
'apigate' => array('POST'),
|
||||||
@@ -136,6 +137,19 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
if ( $endpoint == 'uploads'){
|
if ( $endpoint == 'uploads'){
|
||||||
$local_out=["test_msg"=>'Yes the upload endpoint was hit******** 777'];
|
$local_out=["test_msg"=>'Yes the upload endpoint was hit******** 777'];
|
||||||
$call_backend = false; // will be decided after file is saved
|
$call_backend = false; // will be decided after file is saved
|
||||||
|
|
||||||
|
$raw_json = flatten(json_decode(file_get_contents('php://input'), true));
|
||||||
|
$raw_array = json_decode($raw_json, true);
|
||||||
|
$raw_array["call_backend"] = $call_backend;
|
||||||
|
$ll = reciveUpload($raw_array, $local_out);
|
||||||
|
$raw_array["call_backend"] = $local_out["call_backend"];
|
||||||
|
$raw_array["message"] = $local_out["message"];
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$in = flatten(json_decode(file_get_contents('php://input'), true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// $call_backend = false;
|
// $call_backend = false;
|
||||||
if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) {
|
if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) {
|
||||||
@@ -143,9 +157,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
||||||
$in = flatten(json_decode(file_get_contents('php://input'), true));
|
|
||||||
}
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
|
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
|
||||||
parse_str(file_get_contents('php://input'), $in);
|
parse_str(file_get_contents('php://input'), $in);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user