diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ad1d3874..1c8b6002 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -42,6 +42,7 @@ $routes->post("add_advertise_image", "AppContentManagementController::add_advert $routes->get("add_image_index", "AppContentManagementController::add_image_index"); $routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1"); $routes->get("frontend_content", "AppContentManagementController::frontend_content"); +$routes->get('showAdvertiseImage/(:any)', 'AdvertiseController::showAdvertiseImage/$1'); // $routes->get('/', 'LoginController::index'); diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index 33d6ce1d..f9e1d356 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -40,36 +40,58 @@ class AppContentManagementController extends AdminController // $this->loadLayout('client_onboarding', $data); } - public function add_advertise_image(){ + public function add_advertise_image() { + try { + $file = $this->request->getFile('advertise_image'); + //1) original file name for vaildations + $fileName = $file->getClientName(); //original file name for vaildations + $existing = $this->addImgModel->where('name', $fileName)->where('is_active', 1)->first(); + if($existing){ return $this->respond(['status' => false, 'message' => 'This file has already been uploaded in active state.'], 400); } - // print_r($this->request->getPost());die; - $uploadFilePath = ROOTPATH . 'public/uploads/advertiseImage/'; - $file_name = file_Upload($this->request->getFile('advertise_image'), $uploadFilePath); - $data['id'] = $this->request->getPost('add_image_id'); - // $data['created_by'] = get_session_userid(); - $data['name'] = $file_name; + //skip 1) and use this + // $fileName = $file->getRandomName(); // Same Name Multiple time upload means different name - if($data['id'] == 0){ - $insert = $this->addImgModel->insert($data); - if($insert){ - return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + if (!$file || !$file->isValid()) { + return $this->respond(['status' => false, 'message' => 'No file uploaded or invalid file.'], 400); + } - }else{ - return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + if (!is_dir($uploadPath)) mkdir($uploadPath, 0755, true); - } - }else{ - $id = $data['id']; - $update = $this->addImgModel->update($id,$data); - if($update){ - return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + + $file->move($uploadPath, $fileName); - }else{ - return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); - } + $id = $this->request->getPost('add_image_id'); + $data = ['name' => $fileName]; + + if ($id == 0) { + $this->addImgModel->insert($data); + } else { + $this->addImgModel->update($id, $data); + } + + return $this->respond(['status' => true, 'message' => 'Image saved successfully.']); + } catch (\Exception $e) { + return $this->respond(['status' => false, 'message' => $e->getMessage()], 500); } } + public function showAdvertiseImage($fileName) + { + + $filePath = WRITEPATH . 'uploads/advertiseImage/' . $fileName; + + if (!file_exists($filePath)) { + return $this->response->setStatusCode(404, 'File not found'); + } + + $mimeType = mime_content_type($filePath); + header('Content-Type: ' . $mimeType); + readfile($filePath); + exit; + } + + public function getAdvertiseImage($image_id){ $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php index 5d8d65ad..52f4a658 100755 --- a/app/Views/add_image_list.php +++ b/app/Views/add_image_list.php @@ -53,7 +53,7 @@ table.dataTable thead th { @@ -82,17 +82,15 @@ table.dataTable thead th { -
- - + +
- +
@@ -101,8 +99,9 @@ table.dataTable thead th {
+
- +
@@ -113,68 +112,69 @@ table.dataTable thead th { \ No newline at end of file diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 3b21c09d..fdb0c39e 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -51,23 +51,24 @@ position: relative; width: 50px; height: 25px; -background-color: #fff; +background-color: #cccccc; border-radius: 25px; box-shadow: 0 0 5px rgba(0,0,0,0.2); transition: 0.3s; } -.slider::before , +/* Round knob (always white) */ +.slider::before, .slider_blue::before { -content: ""; -position: absolute; -height: 19px; -width: 19px; -left: 3px; -top: 3px; -background-color: #ccc; -border-radius: 50%; -transition: 0.3s; + content: ""; + position: absolute; + height: 19px; + width: 19px; + left: 3px; + top: 3px; + background-color: #fff; /* always white */ + border-radius: 50%; + transition: 0.3s; } input:checked + .slider {