D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Gallery.php
back
Copy
<?php class Gallery extends CI_controller{ public function __construct() { # code... parent::__construct(); $admin = $this->session->userdata('admin'); if(empty($admin)){ $this->session->set_flashdata('msg', 'Your session has been expired'); redirect(base_url('admin/login/index')); } } public function create() { // ====>view code start # code... $data = []; // for sidebar $data['mainModule'] = 'gallery'; $data['subModule'] = 'gallery'; $this->load->library('form_validation'); $this->load->model('Gallery_model'); $gallery = $this->Gallery_model->getGallery(); $data['gallery'] = $gallery; // ===>view code end # code... $config['upload_path'] = './public/uploads/gallery/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->form_validation->set_rules('text1', 'Text1', 'trim|required'); $this->form_validation->set_rules('text2', 'Text2', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run() == true){ // here we will upload data if(!empty($_FILES['image']['name'])){ if($this->upload->do_upload('image')){ $data = $this->upload->data(); $formArray['text1'] = $this->input->post('text1'); $formArray['text2'] = $this->input->post('text2'); $formArray['pic'] = $data['file_name']; $formArray['date'] = date('Y-m-d H:i:s'); $this->Gallery_model->addGallery($formArray); $this->session->set_flashdata('success', 'Gallery Added Successfully!'); redirect(base_url().'admin/gallery/create'); }else{ $error = $this->upload->display_errors('<p class="invalid-feedback">', '</p>'); $data['error'] = $error; $this->session->set_flashdata('error', 'Sorry something went wrong!'); redirect(base_url().'admin/gallery/create'); } }else{ $this->session->set_flashdata('error', 'Sorry something went wrong!'); redirect(base_url().'admin/gallery/create'); } }else{ $this->load->view('admin/gallery', $data); } } public function delete($id) { # code... $this->load->model('Gallery_model'); $gal = $this->Gallery_model->getGal($id); if(empty($gal)){ $this->session->set_flashdata('error', 'Gallery not found!'); redirect(base_url().'admin/gallery/create'); }else{ if(file_exists('./public/uploads/gallery/'.$gal[0]['pic'])){ unlink('./public/uploads/gallery/'.$gal[0]['pic']); } $this->Gallery_model->deleteGal($id); $this->session->set_flashdata('success', 'Gallery deleted successfully!'); redirect(base_url().'admin/gallery/create'); } } public function getDataAjax($id) { # code... $this->load->model('Gallery_model'); $temp_gal = $this->Gallery_model->getGal($id); $gal = json_encode($temp_gal); echo $gal; } public function edit() { # code... # code... $config['upload_path'] = './public/uploads/gallery/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->library('form_validation'); $this->load->model('Gallery_model'); $this->form_validation->set_rules('etext1', 'Text1', 'trim|required'); $this->form_validation->set_rules('etext2', 'Text2', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==true){ // main threat for updation ---> $id = $this->input->post('eid'); if(!empty($_FILES['eimage']['name'])){ if($this->upload->do_upload('eimage')){ $data = $this->upload->data(); // unlink the older file first $gal = $this->Gallery_model->getGal($id); $path = './public/uploads/gallery/'.$gal[0]['pic']; if(file_exists($path)){ unlink($path); } $formArray = []; $formArray['text1'] = $this->input->post('etext1'); $formArray['text2'] = $this->input->post('etext2'); $formArray['pic'] = $data['file_name']; $this->Gallery_model->editGallery($id, $formArray); $this->session->set_flashdata('success', 'Gallery Updated Successfully!'); redirect(base_url().'admin/gallery/create'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorFileUpload'] = $error; redirect(base_url().'admin/gallery/create'); } }else{ $formArray = []; $formArray['text1'] = $this->input->post('etext1'); $formArray['text2'] = $this->input->post('etext2'); $this->Gallery_model->editGallery($id, $formArray); $this->session->set_flashdata('success', 'Gallery Updated Successfully!'); redirect(base_url().'admin/gallery/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/gallery/create'); } } }