|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/ptbos.biz/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Location extends Admin_Controller {
function __construct() {
parent::__construct();
$this->load->model('location_m');
}
public function index() {
$this->edit(1);
}
public function edit($id = NULL) {
$count = $this->location_m->count_exist($id);
if ($count == 0) {
show_404();
}
$this->data['location'] = $this->location_m->get($id);
$config = array(
array(
'field' => 'text',
'label' => 'text',
'rules' => 'trim'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if ($this->form_validation->run() == TRUE) {
if($_POST) {
if ($_FILES['userfile1']['size'] !== 0) {
$config['upload_path'] = './uploads/location/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '1024';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile1')) {
// echo $this->upload->display_errors(); die();
$this->session->set_flashdata('error1', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
redirect('admin/location/edit/' . $id);
} else {
$image1 = $this->upload->data();
$image_filename1 = $image1['file_name'];
}
}
if ($_FILES['userfile2']['size'] !== 0) {
$config['upload_path'] = './uploads/location/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '1024';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile2')) {
//echo $this->upload->display_errors(); die();
$this->session->set_flashdata('error2', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
redirect('admin/location/edit/' . $id);
} else {
$image2 = $this->upload->data();
$image_filename2 = $image2['file_name'];
}
}
if ($_FILES['userfile3']['size'] !== 0) {
$config['upload_path'] = './uploads/location/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '1024';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile3')) {
//echo $this->upload->display_errors(); die();
$this->session->set_flashdata('error3', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
redirect('admin/location/edit/' . $id);
} else {
$image3 = $this->upload->data();
$image_filename3 = $image3['file_name'];
}
}
}
$data = array(
'text' => $this->security->xss_clean($this->input->post('text')),
'text2' => $this->security->xss_clean($this->input->post('text2')),
'text3' => $this->security->xss_clean($this->input->post('text3')),
'text4' => $this->security->xss_clean($this->input->post('text4')),
);
//image upload
if (isset($image_filename1)) {
$data['image1'] = $image_filename1;
}
//image upload
if (isset($image_filename2)) {
$data['image2'] = $image_filename2;
}
//image upload
if (isset($image_filename3)) {
$data['image3'] = $image_filename3;
}
$this->location_m->edit_location($id, $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Location Edit Successful</p>');
redirect('admin/location');
}
$this->db->select('*');
$this->db->from('configuration');
$data['config'] = $this->db->get()->result();
foreach ($data['config'] as $item) {
$this->data_header['image'] = $item->logo;
$this->data_header['icon'] = $item->website_icon;
}
$this->data['subview'] = 'admin/location/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
public function delete_image($image_number = NULL) {
if($image_number == NULL) { show_404(); }
//get image file name for deletion
$this->db->select('image1,image2,image3');
$this->db->from('location');
$this->db->where('id_location', 1);
switch($image_number) {
case '':
$image = $this->db->get()->row()->image;
break;
case '2':
$image = $this->db->get()->row()->image2;
break;
case '3':
$image = $this->db->get()->row()->image3;
break;
}
//Delete the actual image file from server. FCPATH is codeigniter base path
unlink(FCPATH .'uploads/location/'. $image);
//Delete image field from database
$data = array(
'image' . $image_number => '',
);
$this->db->where('id_location', 1);
$this->db->update('location', $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Location Image Delete Successful</p>');
redirect('admin/location');
}
}