File manager - Edit - /home/u608250662/domains/rdsolution.org.in/public_html/jevica/application/controllers/Categories.php
Back
<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); class Categories extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); } function listing() { $data['CATGDATA'] = $this->categoriess->selectallcatg(); $this->load->view('admin/categories/list', $data); } // function add() // { // if (isset($_POST['submit'])) { // if ($_FILES['image']['name'] != "") { // $bimage = $_FILES['image']['name']; // $path = 'media/uploads/category/products' . $bimage; // move_uploaded_file($_FILES['image']['tmp_name'], $path); // } else { // $bimage = ""; // } // $data['category'] = $this->input->post('title'); // $data['caturl'] = $this->input->post('url'); // $data['imgalt'] = $this->input->post('imgalt'); // $data['pcat'] = implode('#', $this->input->post('pcat')); // $data['showonmenu'] = $this->input->post('showonmenu'); // $data['seotitle'] = $this->input->post('seotitle'); // $data['seokeyword'] = $this->input->post('seokeyword'); // $data['seodesc'] = $this->input->post('seodesc'); // echo $data['image'] = $bimage; // // echo $pcatarray = $this->input->post('pcat'); // // echo "<pre>"; // // print_r($data); // // exit(); // $this->categoriess->insert($data); // $this->session->set_flashdata('message', '<div class="alert alert-success">Record has been successfully saved.</div>'); // redirect('categories/listing'); // } // $data['CATDATA'] = $this->crud->fetchAllData('blue_category'); // $data['SUBCATDATA'] = $this->crud->fetchAllData('blue_sub_category'); // $this->load->view('admin/categories/add', $data); // } public function add() { if (isset($_POST['submit'])) { $data = []; // ========================= // IMAGE UPLOAD // ========================= // $image = ""; // if (!empty($_FILES['image']['name'])) { // $image = time() . '_' . $_FILES['image']['name']; // $path = FCPATH . 'media/uploads/category/products/' . $image; // move_uploaded_file($_FILES['image']['tmp_name'], $path); // } $uploaded_images = []; if (!empty($_FILES['images']['name'][0])) { foreach ($_FILES['images']['name'] as $key => $name) { if (!empty($name)) { $image_name = time() . '_' . $name; $tmp_name = $_FILES['images']['tmp_name'][$key]; $path = FCPATH . 'media/uploads/category/products/' . $image_name; if (move_uploaded_file($tmp_name, $path)) { $uploaded_images[] = $image_name; } } } } $feature_img = ""; if (!empty($_FILES['feature_image']['name'])) { $feature_img = time() . '_' . $_FILES['feature_image']['name']; $path = FCPATH . 'media/uploads/category/products/' .$feature_img; move_uploaded_file($_FILES['feature_image']['tmp_name'], $path); } // ========================= // PDF UPLOAD // ========================= $pdf = ""; if (!empty($_FILES['pdf']['name'])) { $pdf = time() . '_' . $_FILES['pdf']['name']; $path = FCPATH . 'media/uploads/category/products/pdf/' . $pdf; move_uploaded_file($_FILES['pdf']['tmp_name'], $path); } // ========================= // DOC UPLOAD // ========================= $doc = ""; if (!empty($_FILES['doc']['name'])) { $doc = time() . '_' . $_FILES['doc']['name']; $path = FCPATH . 'media/uploads/category/products/doc/' . $doc; move_uploaded_file($_FILES['doc']['tmp_name'], $path); } $images_string = implode(',', $uploaded_images); // ========================= // DATA ARRAY // ========================= $data = [ 'cate_url' => '', 'sub_cat_url' => '', 'product_name' => $this->input->post('product_name'), 'product_url' => $this->input->post('product_url'), 'product_price' => $this->input->post('product_price'), 'feature_img' => $feature_img, 'image' => $images_string, 'pdf' => $pdf, 'doc' => $doc, 'image_alt' => $this->input->post('image_alt'), 'product_desc' => $this->input->post('product_desc'), 'seotitle' => $this->input->post('seotitle'), 'seokeywords' => $this->input->post('seokeywords'), 'seodesc' => $this->input->post('seodesc'), 'status' => $this->input->post('status'), 'home_page' => $this->input->post('home_page'), 'menu_show' => $this->input->post('menu_show') ]; // ========================= // INSERT // ========================= $this->crud->insert('wdi_category', $data); $this->session->set_flashdata( 'message', '<div class="alert alert-success">Product added successfully.</div>' ); redirect('products/listing'); } // LOAD FORM DATA $data['CATDATA'] = $this->crud->fetchAllData('blue_category'); $data['SUBCATDATA'] = $this->crud->fetchAllData('blue_sub_category'); $this->load->view('admin/categories/add', $data); } public function edit($id) { $product = $this->categoriess->selectcatbyid($id); if (empty($product)) { show_404(); } $product = $product[0]; if (isset($_POST['submit'])) { // ================= OLD IMAGES ================= $old_images = !empty($this->input->post('old_image')) ? explode(',', $this->input->post('old_image')) : []; $new_images = []; // ================= MULTIPLE IMAGE UPLOAD (FIXED) ================= if (!empty($_FILES['images']['name'])) { foreach ($_FILES['images']['name'] as $key => $name) { // 🔴 FIX: skip empty inputs if (empty($name) || $_FILES['images']['error'][$key] == 4) { continue; } $ext = pathinfo($name, PATHINFO_EXTENSION); $allowed = ['jpg','jpeg','png','webp']; if (in_array(strtolower($ext), $allowed)) { $img = uniqid().'.'.$ext; move_uploaded_file( $_FILES['images']['tmp_name'][$key], FCPATH.'media/uploads/category/products/'.$img ); $new_images[] = $img; } } } $final_images = array_filter(array_merge($old_images, $new_images)); $image_string = implode(',', $final_images); // ================= FEATURE IMAGE ================= $feature_img = $product->feature_img; if (!empty($_FILES['feature_img']['name'])) { if (!empty($product->feature_img)) { @unlink(FCPATH.'media/uploads/category/products/'.$product->feature_img); } $feature_img = time().'_'.$_FILES['feature_img']['name']; move_uploaded_file( $_FILES['feature_img']['tmp_name'], FCPATH.'media/uploads/category/products/'.$feature_img ); } // ================= PDF ================= $pdf = $product->pdf; if (!empty($_FILES['pdf']['name'])) { $pdf = time().'_'.$_FILES['pdf']['name']; move_uploaded_file( $_FILES['pdf']['tmp_name'], FCPATH.'media/uploads/category/products/pdf/'.$pdf ); } // ================= DOC ================= $doc = $product->doc; if (!empty($_FILES['doc']['name'])) { $doc = time().'_'.$_FILES['doc']['name']; move_uploaded_file( $_FILES['doc']['tmp_name'], FCPATH.'media/uploads/category/products/doc/'.$doc ); } // ================= UPDATE DATA ================= $data = [ 'cate_url' => '', 'sub_cat_url' => '', 'product_name' => $this->input->post('product_name'), 'product_url' => $this->input->post('product_url'), 'product_price' => $this->input->post('product_price'), 'feature_img' => $feature_img, 'image' => $image_string, 'pdf' => $pdf, 'doc' => $doc, 'image_alt' => $this->input->post('image_alt'), 'product_desc' => $this->input->post('product_desc'), 'seotitle' => $this->input->post('seotitle'), 'seokeywords' => $this->input->post('seokeywords'), 'seodesc' => $this->input->post('seodesc'), 'status' => $this->input->post('status'), 'home_page' => $this->input->post('home_page'), 'menu_show' => $this->input->post('menu_show') ]; $this->crud->update($id, $data, 'wdi_category'); $this->session->set_flashdata( 'message', '<div class="alert alert-success">Product updated successfully.</div>' ); redirect('products/listing'); } $data['product'] = $this->categoriess->selectcatbyid($id); $data['CATDATA'] = $this->crud->fetchAllData('blue_category'); $data['SUBCATDATA'] = $this->crud->fetchAllData('blue_sub_category'); // echo "<pre>";print_r($data);die; $this->load->view('admin/categories/edit', $data); } // public function edit($id) // { // // ========================= // // GET EXISTING PRODUCT // // ========================= // $product = $this->categoriess->selectcatbyid($id); // if (empty($product)) { // show_404(); // } // $product = $product[0]; // if (isset($_POST['submit'])) { // // ========================= // // IMAGE UPLOAD // // ========================= // // $image = $product->image; // // if (!empty($_FILES['image']['name'])) { // // $image = time() . '_' . $_FILES['image']['name']; // // $path = FCPATH . 'media/uploads/category/products/' . $image; // // move_uploaded_file($_FILES['image']['tmp_name'], $path); // // } // $old_images = explode(',', $this->input->post('old_image')); // $new_images = []; // if (!empty($_FILES['images']['name'][0])) { // foreach ($_FILES['images']['name'] as $key => $name) { // $img = uniqid().'_'.$name; // move_uploaded_file($_FILES['images']['tmp_name'][$key], // FCPATH.'media/uploads/category/products/'.$img // ); // $new_images[] = $img; // } // } // $final_images = array_merge($old_images, $new_images); // $image_string = implode(',', $final_images); // $feature_img = $product->feature_img; // if (!empty($_FILES['feature_img']['name'])) { // $feature_img = time() . '_' . $_FILES['pdf']['name']; // $path = FCPATH . 'media/uploads/category/products/' . $feature_img; // move_uploaded_file($_FILES['feature_img']['tmp_name'], $path); // } // // ========================= // // PDF UPLOAD // // ========================= // $pdf = $product->pdf; // if (!empty($_FILES['pdf']['name'])) { // $pdf = time() . '_' . $_FILES['pdf']['name']; // $path = FCPATH . 'media/uploads/category/products/pdf/' . $pdf; // move_uploaded_file($_FILES['pdf']['tmp_name'], $path); // } // // ========================= // // DOC UPLOAD // // ========================= // $doc = $product->doc; // if (!empty($_FILES['doc']['name'])) { // $doc = time() . '_' . $_FILES['doc']['name']; // $path = FCPATH . 'media/uploads/category/products/doc/' . $doc; // move_uploaded_file($_FILES['doc']['tmp_name'], $path); // } // // $images_string = implode(',', $uploaded_images); // // ========================= // // UPDATE DATA (FIXED) // // ========================= // $data = [ // 'cate_url' => $this->input->post('cate_id'), // 'sub_cat_url' => $this->input->post('sub_cat_id'), // 'product_name' => $this->input->post('product_name'), // 'product_url' => $this->input->post('product_url'), // 'feature_img' => $feature_img, // 'image' => $image_string, // 'pdf' => $pdf, // 'doc' => $doc, // 'image_alt' => $this->input->post('image_alt'), // 'product_desc' => $this->input->post('product_desc'), // 'seotitle' => $this->input->post('seotitle'), // 'seokeywords' => $this->input->post('seokeywords'), // 'seodesc' => $this->input->post('seodesc'), // 'status' => $this->input->post('status'), // 'home_page' => $this->input->post('home_page') // ]; // // ========================= // // UPDATE QUERY (IMPORTANT FIX) // // ========================= // $this->crud->update($id,$data,'wdi_category'); // $this->session->set_flashdata( // 'message', // '<div class="alert alert-success">Product updated successfully.</div>' // ); // redirect('products/listing'); // } // // ========================= // // LOAD VIEW DATA // // ========================= // $data['product'] = $this->categoriess->selectcatbyid($id); // $data['CATDATA'] = $this->crud->fetchAllData('blue_category'); // $data['SUBCATDATA'] = $this->crud->fetchAllData('blue_sub_category'); // $this->load->view('admin/categories/edit', $data); // } // function edit() // { // $args = func_get_args(); // if (isset($_POST['submit'])) { // if ($_FILES['image']['name'] != "") { // $bimage = $_FILES['image']['name']; // $path = 'media/uploads/category/' . $bimage; // move_uploaded_file($_FILES['image']['tmp_name'], $path); // } else { // $bimage = $this->input->post('old_image'); // } // $data['category'] = $this->input->post('title'); // $data['caturl'] = $this->input->post('url'); // $data['pcat'] = implode('#', $this->input->post('pcat')); // $data['imgalt'] = $this->input->post('imgalt'); // $data['showonmenu'] = $this->input->post('showonmenu'); // $data['seotitle'] = $this->input->post('seotitle'); // $data['seokeyword'] = $this->input->post('seokeyword'); // $data['seodesc'] = $this->input->post('seodesc'); // $data['image'] = $bimage; // $this->categoriess->update($args[0], $data); // $this->session->set_flashdata('message', '<div class="alert alert-success">Record has been successfully updated.</div>'); // redirect('categories/listing'); // } // $data['CATDATA'] = $this->crud->fetchAllData('blue_category'); // $data['SUBCATDATA'] = $this->crud->fetchAllData('blue_sub_category'); // $data['product'] = $this->categoriess->selectcatbyid($args[0]); // // echo "<pre>"; // // print_r($data); // // exit(); // $this->load->view('admin/categories/edit', $data); // } function delete() { $args = func_get_args(); $data = $this->categoriess->selectcatbyid($args[0]); $image = 'media/uploads/category/products/' . $data[0]->image; $pdf = 'media/uploads/category/products/pdf/' . $data[0]->pdf; $doc = 'media/uploads/category/products/doc/' . $data[0]->doc; @unlink($image); @unlink($pdf); @unlink($doc); $this->categoriess->delete($args[0]); $this->session->set_flashdata('message', '<div class="alert alert-success">Record has been successfully deleted.</div>'); redirect('products/listing'); } public function get_subcategory() { $category_id = $this->input->post('category_id'); if (empty($category_id)) { echo '<option value="">Select Sub Category</option>'; return; } $this->load->model('Categoriess'); $subcategories = $this->Categoriess->get_subcategories_by_category($category_id); $html = '<option value="">Select Sub Category</option>'; if (!empty($subcategories)) { foreach ($subcategories as $row) { $html .= '<option value="' . $row->sub_category_url . '">' . $row->sub_category . '</option>'; } } echo $html; } public function delete_product_image($product_id, $image_name) { // 🔥 STEP 1: decode base64 FIRST (IMPORTANT) $image_name = base64_decode(urldecode($image_name)); $product = $this->db->where('id', $product_id) ->get('wdi_category') ->row(); if(!$product){ show_404(); } // 🔥 STEP 2: clean image list $images = explode(',', $product->image); $updated_images = array_filter($images, function($img) use ($image_name){ return trim($img) != trim($image_name); }); // 🔥 STEP 3: update DB $this->db->where('id', $product_id)->update('wdi_category', [ 'image' => implode(',', $updated_images) ]); // 🔥 STEP 4: correct file path $file_path = FCPATH . 'media/uploads/category/products/' . $image_name; // DEBUG (remove after testing) if(!file_exists($file_path)){ die("File not found: " . $file_path); } // 🔥 STEP 5: delete file safely if(file_exists($file_path)){ unlink($file_path); } redirect($_SERVER['HTTP_REFERER']); } }
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings