Beispiel #1
0
 public function upload_image()
 {
     $this->load->helper('directory');
     $products_id = $this->input->get_post('products_id');
     if (is_array($_FILES)) {
         $images = array_keys($_FILES);
     }
     if (!empty($images)) {
         if (empty($products_id)) {
             $image_path = ROOTPATH . 'images/products/_upload/' . $this->session->userdata('session_id') . '/';
             if (directory_make($image_path)) {
                 $config['upload_path'] = $image_path;
                 $config['allowed_types'] = 'gif|jpg|png';
                 $this->load->library('upload', $config);
                 foreach ($images as $image) {
                     if (!$this->upload->do_upload($image)) {
                         $error = array('error' => $this->upload->display_errors());
                     }
                 }
             }
         } else {
             $image_path = ROOTPATH . 'images/products/originals/';
             $config['upload_path'] = $image_path;
             $config['allowed_types'] = 'gif|jpg|png';
             $this->load->library('upload', $config);
             foreach ($images as $image) {
                 if ($this->upload->do_upload($image)) {
                     $data = $this->upload->data();
                     $this->products_model->do_edit_upload($products_id, $data['file_name']);
                 }
             }
         }
     }
     if (empty($error)) {
         $response['success'] = true;
         $response['feedback'] = lang('ms_success_action_performed');
     } else {
         $response['success'] = false;
         $response['feedback'] = lang('ms_success_action_not_performed') . $error;
     }
     $this->output->set_header("Content-Type: text/html")->set_output(json_encode($response));
     return NULL;
 }
Beispiel #2
0
 /**
  * Upload the product image
  * 
  * @access public
  * @return string
  */
 public function upload_image()
 {
     $products_id = $this->input->get_post('products_id');
     //error check flag
     $error = FALSE;
     $error_msg = '';
     //get the uploaded product images
     if (is_array($_FILES)) {
         $images = array_keys($_FILES);
     } else {
         $error = TRUE;
     }
     if ($error === FALSE) {
         if (!empty($images)) {
             //load the ci upload
             $this->load->library('upload');
             $config['allowed_types'] = 'gif|jpg|png|jpeg';
             //editing the product
             if ((int) $products_id > 0) {
                 //init upload
                 $config['upload_path'] = ROOTPATH . 'images/products/originals/';
                 $this->upload->initialize($config);
                 //upload images
                 foreach ($images as $image) {
                     if ($this->upload->do_upload($image)) {
                         $this->products_model->do_edit_upload($products_id, $this->upload->data('file_name'));
                     } else {
                         $error = TRUE;
                         $error_msg .= $this->upload->display_errors();
                     }
                 }
             } else {
                 $image_path = ROOTPATH . 'images/products/_upload/' . $this->session->userdata('session_id') . '/';
                 if (directory_make($image_path)) {
                     //init upload
                     $config['upload_path'] = $image_path;
                     $this->upload->initialize($config);
                     //upload images
                     foreach ($images as $image) {
                         if (!$this->upload->do_upload($image)) {
                             $error = TRUE;
                             $error_msg .= $this->upload->display_errors();
                         }
                     }
                 } else {
                     $error = TRUE;
                 }
             }
         }
     }
     if ($error === FALSE) {
         $response = array('success' => TRUE, 'feedback' => lang('ms_success_action_performed'));
     } else {
         $response = array('success' => FALSE, 'feedback' => lang('ms_success_action_not_performed') . $error_msg);
     }
     $this->output->set_header("Content-Type: text/html")->set_output(json_encode($response));
 }
 /**
  * Save an article
  *
  * @access public
  * @param $id
  * @param $data
  * @return boolean
  */
 public function save($id = NULL, $data)
 {
     //load libraries
     $this->load->library(array('image', 'upload'));
     //load helpers
     $this->load->helper(array('html_output', 'directory'));
     //flag to check errors
     $error = FALSE;
     //start transaction
     $this->db->trans_begin();
     //article information
     $article_info = array('articles_status' => $data['articles_status'], 'articles_order' => $data['articles_order'], 'articles_categories_id' => $data['articles_categories']);
     //editing article
     if (is_numeric($id)) {
         $article_info['articles_last_modified'] = date('Y-m-d H:i:s');
         $this->db->update('articles', $article_info, array('articles_id' => $id));
     } else {
         $article_info['articles_date_added'] = date('Y-m-d H:i:s');
         $article_info['articles_last_modified'] = date('Y-m-d H:i:s');
         $this->db->insert('articles', $article_info);
     }
     if ($this->db->trans_status() === FALSE) {
         $error = TRUE;
     } else {
         //get the article id as inserting the new article
         $articles_id = is_numeric($id) ? $id : $this->db->insert_id();
     }
     //articles images
     if ($error === FALSE && $data['delimage'] == 1) {
         $this->image->delete_articles_image($articles_id);
         $this->db->update('articles', array('articles_image' => NULL), array('articles_id' => $articles_id));
         if ($this->db->trans_status() === FALSE) {
             $error = TRUE;
         }
     }
     //upload article image
     if ($error === FALSE) {
         //create the directory to store articles images
         if (!is_dir(ROOTPATH . 'images/articles')) {
             directory_make(ROOTPATH . 'images/articles');
             directory_make(ROOTPATH . 'images/articles/originals');
         }
         //check whether the uploaded image is existed
         if (isset($_FILES[$data['articles_image']]) && isset($_FILES[$data['articles_image']]['tmp_name']) && !empty($_FILES[$data['articles_image']]['tmp_name']) && is_uploaded_file($_FILES[$data['articles_image']]['tmp_name'])) {
             $config['upload_path'] = ROOTPATH . 'images/articles/originals';
             //only the gif, jpg, png, jpeg are allowed to be uploaded
             $config['allowed_types'] = 'gif|jpg|png|jpeg';
             $this->upload->initialize($config);
             //upload the image now
             if ($this->upload->do_upload($data['articles_image'])) {
                 //upload the articles image field in the database
                 $this->db->update('articles', array('articles_image' => $this->upload->data('file_name')), array('articles_id' => $articles_id));
                 if ($this->db->trans_status() === FALSE) {
                     $error = TRUE;
                 } else {
                     //resize the image for each image group
                     foreach ($this->image->get_groups() as $group) {
                         if ($group['id'] !== 1) {
                             $this->image->resize($this->upload->data('file_name'), $group['id'], 'articles');
                         }
                     }
                 }
             } else {
                 $error = TRUE;
             }
         }
     }
     //Process articles description for each language
     if ($error === FALSE) {
         foreach (lang_get_all() as $l) {
             $articles_description = array('articles_name' => $data['articles_name'][$l['id']], 'articles_url' => $data['articles_url'][$l['id']], 'articles_description' => $data['articles_description'][$l['id']], 'articles_page_title' => $data['page_title'][$l['id']], 'articles_meta_keywords' => $data['meta_keywords'][$l['id']], 'articles_meta_description' => $data['meta_description'][$l['id']]);
             //editing article
             if (is_numeric($id)) {
                 $this->db->update('articles_description', $articles_description, array('articles_id' => $articles_id, 'language_id' => $l['id']));
             } else {
                 $articles_description['articles_id'] = $articles_id;
                 $articles_description['language_id'] = $l['id'];
                 $this->db->insert('articles_description', $articles_description);
             }
             if ($this->db->trans_status() === FALSE) {
                 $error = TRUE;
                 break;
             }
         }
     }
     if ($error === FALSE) {
         //commit transaction
         $this->db->trans_commit();
         return TRUE;
     }
     //rollback
     $this->db->trans_rollback();
     return FALSE;
 }
 function dircopy($src, $dest, $folder_permission = 0755, $file_permission = 0644)
 {
     $res = false;
     $src = str_replace('\\', '/', $src);
     $src = str_replace('//', '/', $src);
     $dest = str_replace('\\', '/', $dest);
     $dest = str_replace('//', '/', $dest);
     //file copy
     if (is_file($src)) {
         if (is_dir($dest)) {
             if ($dest[strlen($dest) - 1] != '/') {
                 $__dest = $dest . "/";
             }
             $__dest .= basename($src);
         } else {
             $__dest = $dest;
         }
         $res = copy($src, $__dest);
         chmod($__dest, $file_permission);
     } elseif (is_dir($src)) {
         if (!is_dir($dest)) {
             directory_make($dest, $folder_permission);
             chmod($dest, $folder_permission);
         }
         if ($src[strlen($src) - 1] != '/') {
             $__src = $src . '/';
         } else {
             $__src = $src;
         }
         if ($dest[strlen($dest) - 1] != '/') {
             $__dest = $dest . '/';
         } else {
             $__dest = $dest;
         }
         $res = true;
         $handle = opendir($src);
         while ($file = readdir($handle)) {
             if ($file != '.' && $file != '..') {
                 $res = dircopy($__src . $file, $__dest . $file, $folder_permission, $file_permission);
             }
         }
         closedir($handle);
     } else {
         $res = false;
     }
     return $res;
 }