AJAX file upload and size limit
This commit is contained in:
@@ -280,8 +280,8 @@ class Proj extends Users_Controller {
|
||||
public function latejob() {
|
||||
// echo 'oooooooooooooooooooooooooo';
|
||||
// $data['redirect_to'] = str_replace(base_url(),'',$_SERVER['HTTP_REFERER']);
|
||||
|
||||
$data = $this->getSessionArray();
|
||||
$uploaded = false;
|
||||
$data = $this->getSessionArray();
|
||||
|
||||
$data['redirect_to'] = '/proj/pastdue/';
|
||||
|
||||
@@ -318,7 +318,7 @@ class Proj extends Users_Controller {
|
||||
// print_r( $out );
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
$message = $this->process_files($_FILES["fileToUpload"]);
|
||||
list ($message, $uploaded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
}
|
||||
|
||||
$data = $this->load_files($data, $jobID);
|
||||
@@ -367,26 +367,32 @@ class Proj extends Users_Controller {
|
||||
public function thisjob() {
|
||||
$data = $this->getSessionArray();
|
||||
$data['redirect_to'] = '/proj/active/';
|
||||
$uploaded = false;
|
||||
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
redirect(home);
|
||||
} else {
|
||||
$message = "";
|
||||
// echo rand(100,9999). " ameye 1";
|
||||
|
||||
$ajax = $this->input->post('ajax');
|
||||
$jobID = $this->input->post('jobID');
|
||||
// echo rand(100,9999). " ameye 1";
|
||||
|
||||
if ($_POST) {
|
||||
$ajax = $this->input->post('ajax');
|
||||
$jobID = $this->input->post('jobID');
|
||||
} else {
|
||||
$ajax = $this->input->get('ajax');
|
||||
$jobID = $this->input->get('jobID');
|
||||
$message = $this->input->get('message');
|
||||
}
|
||||
$data['jobID'] = $jobID;
|
||||
|
||||
//$mybalance = 10666;
|
||||
//$data['mybalance'] = $mybalance;
|
||||
|
||||
$this->load->model('backend_model');
|
||||
// echo rand(100,9999). " ameye 2";
|
||||
// echo rand(100,9999). " ameye 2";
|
||||
if ($_POST && !isset($_POST['uploadForm'])) {
|
||||
// echo rand(100,9999). " ameye 2222-2222";
|
||||
// exit;
|
||||
// echo rand(100,9999). " ameye 2222-2222";
|
||||
// exit;
|
||||
$msgArray = array();
|
||||
$msgArray['message'] = trim($this->input->post('jobmessage'));
|
||||
$msgArray['contract'] = $this->input->post('contractId');
|
||||
@@ -401,7 +407,7 @@ class Proj extends Users_Controller {
|
||||
$res = $this->backend_model->wrenchboard_api($msgArray, $out);
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
$message = $this->process_files($_FILES["fileToUpload"]);
|
||||
list ($message, $uploaded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
}
|
||||
|
||||
$data = $this->load_files($data, $jobID);
|
||||
@@ -452,12 +458,17 @@ class Proj extends Users_Controller {
|
||||
/* $this->load->view('users/view_header_user', $data);
|
||||
$this->load->view('jobs/view_thisjob', $data);
|
||||
$this->load->view('users/view_footer_user', $data); */
|
||||
$this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
if ($uploaded) {
|
||||
redirect('/proj/thisjob?jobID='.$jobID.'&message='.$message);
|
||||
} else {
|
||||
$this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function mycompltjob() {
|
||||
$uploaded = false;
|
||||
$data = $this->getSessionArray();
|
||||
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
@@ -493,7 +504,7 @@ class Proj extends Users_Controller {
|
||||
// print_r( $out );
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
$message = $this->process_files($_FILES["fileToUpload"]);
|
||||
list ($message, $uploaded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
}
|
||||
|
||||
$this->load->model('dash_model');
|
||||
@@ -546,7 +557,8 @@ class Proj extends Users_Controller {
|
||||
|
||||
public function compltjob() {
|
||||
// echo 'oooooooooooooooooooooooooo';
|
||||
$data = $this->getSessionArray();
|
||||
$uploaded = false;
|
||||
$data = $this->getSessionArray();
|
||||
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
redirect(home);
|
||||
@@ -581,7 +593,7 @@ $data = $this->getSessionArray();
|
||||
// print_r( $out );
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
$message = $this->process_files($_FILES["fileToUpload"]);
|
||||
list ($message, $upaloded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
}
|
||||
|
||||
$this->load->model('dash_model');
|
||||
@@ -649,7 +661,7 @@ $data = $this->getSessionArray();
|
||||
//$detail_button = " '<button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"modal\" data-target=\"#modal_theme_primary\">Delvery Detail<i class=\"icon-play3 position-right\"></i></button>' ";
|
||||
|
||||
$detail_button =" '<a href=\"#\" onclick=\"showJobModal('''||mc.contract||''');\" >Delivery Detail</a>' ";
|
||||
//$detail_button = " '<a href=\"#modal_theme_primary\" class=\"label label-flat border-primary text-primary-600\" data-target=\"#modal_theme_primary\">Linked label</a>' "; // <button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"modal\" data-target=\"#modal_theme_primary\">Delvery Detail<i class=\"icon-play3 position-right\"></i></button>' ";
|
||||
//$detail_button = " '<a href=\"#modal_theme_primary\" class=\"label label-flat border-primary text-primary-600\" data-target=\"#modal_theme_primary\">Linked label</a>' "; // <button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"modal\" data-target=\"#modal_theme_primary\">Delvery Detail<i class=\"icon-play3 position-right\"></i></button>' ";
|
||||
|
||||
|
||||
$is_live = $this->backend_model->cfgReadChar("system.live");
|
||||
@@ -710,7 +722,7 @@ $data = $this->getSessionArray();
|
||||
$this->table->set_template($this->template_nohead);
|
||||
$this->table->set_heading('');
|
||||
$data['message_table'] = $this->table->generate($query_message);
|
||||
//===================
|
||||
//===================
|
||||
|
||||
$data['message_result'] = $query_message->result();
|
||||
|
||||
@@ -1024,11 +1036,11 @@ $data = $this->getSessionArray();
|
||||
$data['new_message'] = $out['new_message'];
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
$this->load->view('users/view_header_user', $data);
|
||||
$this->load->view('jobs/view_mycompletejob', $data);
|
||||
$this->load->view('users/view_footer_user', $data);
|
||||
*/
|
||||
*/
|
||||
$data['page_title'] ="Previous Tasks";
|
||||
$this->renderSecurePage('jobs/view_mycompletejob', $data);
|
||||
}
|
||||
@@ -1038,6 +1050,7 @@ $data = $this->getSessionArray();
|
||||
* This is the file upload function
|
||||
*/
|
||||
private function process_files($files) {
|
||||
$uploaded = false;
|
||||
$result = "";
|
||||
$d_txt = "";
|
||||
$is_live = $this->backend_model->cfgReadChar("system.live");
|
||||
@@ -1066,11 +1079,44 @@ $data = $this->getSessionArray();
|
||||
}
|
||||
}
|
||||
$result = $i > 0 ? "Uploaded file(s): ${i}" : "Failed to process uploaded files${d_txt}";
|
||||
$uploaded = $i > 0;
|
||||
} else {
|
||||
$result = "Files were not uploaded${d_txt}";
|
||||
}
|
||||
// echo $result;
|
||||
return $result;
|
||||
// echo $result;
|
||||
return array($result, $uploaded);
|
||||
}
|
||||
|
||||
public function upload() {
|
||||
$data = $this->getSessionArray();
|
||||
|
||||
$jobID = $this->input->post('jobID');
|
||||
$contractId = $this->input->post('contractId');
|
||||
|
||||
$files = array(
|
||||
"name" => array($_FILES["fileToUpload"]["name"]),
|
||||
"error" => array($_FILES["fileToUpload"]["error"]),
|
||||
"tmp_name" => array($_FILES["fileToUpload"]["tmp_name"]),
|
||||
"size" => array($_FILES["fileToUpload"]["size"]),
|
||||
"type" => array($_FILES["fileToUpload"]["type"])
|
||||
);
|
||||
|
||||
list ($message, $uploaded) = $this->process_files($files);
|
||||
|
||||
if ($uploaded) {
|
||||
header("Content-Type:application/json");
|
||||
echo json_encode(
|
||||
array(
|
||||
"status"=>1,
|
||||
"message"=> ($message != '' ? $message : "File upload failed with an unexpected error.")
|
||||
));
|
||||
} else {
|
||||
header("Content-Type:application/json");
|
||||
echo json_encode(
|
||||
array(
|
||||
"status"=>0,
|
||||
"message"=> ($message != '' ? $message : "Sorry, there was an error uploading your file.")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user