예제 #1
0
 function __construct($options = null, $initialize = false, $error_messages = null)
 {
     parent::__construct();
     $this->load->helper('file');
     $this->options = array('script_url' => $this->get_full_url() . '/', 'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')) . '/' . upload_folder('temp') . '/', 'upload_url' => $this->get_full_url() . '/' . upload_folder('temp') . '/', 'user_dirs' => false, 'mkdir_mode' => 0755, 'param_name' => 'files', 'delete_type' => 'DELETE', 'access_control_allow_origin' => '*', 'access_control_allow_credentials' => false, 'access_control_allow_methods' => array('OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'), 'access_control_allow_headers' => array('Content-Type', 'Content-Range', 'Content-Disposition'), 'download_via_php' => false, 'readfile_chunk_size' => 10 * 1024 * 1024, 'inline_file_types' => '/\\.(gif|jpe?g|png)$/i', 'accept_file_types' => '/.+$/i', 'max_file_size' => null, 'min_file_size' => 1, 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => true, 'image_versions' => array('thumbnail' => array('max_width' => 120, 'max_height' => 90)));
     if ($options) {
         $this->options = array_merge($this->options, $options);
     }
     if ($error_messages) {
         $this->error_messages = array_merge($this->error_messages, $error_messages);
     }
     // if ($initialize) {
     //     $this->initialize();
     // }
 }
예제 #2
0
파일: recycle.php 프로젝트: JokeLook/one
 public function delete($id)
 {
     if (!$id) {
         echo json_encode(array('code' => '1003', 'msg' => '参数错误'));
         exit;
     }
     if ($this->product->delete($id)) {
         $data = array('code' => '1000', 'msg' => '删除成功', 'data' => array('id' => $id));
         @unlink(upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id) . DIRECTORY_SEPARATOR . file_save_name($id) . '.png');
         @unlink(upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id) . DIRECTORY_SEPARATOR . file_save_name($id) . '_thumb.png');
     } else {
         $data = array('code' => '1001', 'msg' => '删除失败');
     }
     echo json_encode($data);
 }
예제 #3
0
파일: newss.php 프로젝트: norain2050/one
 /**
  *   取商品图片
  *   @param int id 商品ID
  *   @param var type 类型
  */
 public function pic($id, $type = 'big')
 {
     $default = base_url() . 'images/default_' . $type . '.jpg';
     if ($id) {
         $this->load->helper('file');
         $dir = upload_dir($id);
         $filePath = '';
         if ($type == 'big') {
             $filePath = upload_folder('product') . '/' . $dir . '/cover.png';
         } else {
             if ($type == 'small') {
                 $filePath = upload_folder('product') . '/' . $dir . '/cover_thumb.png';
             }
         }
         if (file_exists($filePath)) {
             return base_url() . $filePath . '?' . rand();
         }
     }
     return $default;
 }
예제 #4
0
파일: product.php 프로젝트: JokeLook/one
 /**
  *   取商品图片
  *   @param int id 商品ID
  *   @param var type 类型
  */
 public function pic($id = '', $sort = 1, $type = 'big')
 {
     $filePath = $file_save_dir = $file_save_name = '';
     $folder = upload_folder('product');
     if ($id) {
         $file_save_dir = file_save_dir($id);
         $file_save_name = file_save_name($id);
     }
     switch ($type) {
         case 'small':
         case 'thumb':
             $filePath = $folder . '/' . $file_save_dir . '/' . $file_save_name . '_' . $sort . '_thumb.png';
             $default = base_url() . 'assets/img/product/p-default_thumb.png';
             break;
         case 'big':
         case 'default':
         default:
             $filePath = $folder . '/' . $file_save_dir . '/' . $file_save_name . '_' . $sort . '.png';
             $default = base_url() . 'assets/img/product/p-default.png';
             break;
     }
     if (file_exists($filePath)) {
         return base_url() . $filePath . '?' . rand();
     } else {
         return $default;
     }
     return false;
 }
예제 #5
0
 public function update()
 {
     $post = $this->input->post();
     if (empty($post)) {
         show_error('参数错误');
     }
     $data = array('code' => '1000', 'msg' => '');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', ' ', 'required|max_length[50]');
     $this->form_validation->set_rules('info', ' ', 'max_length[100]');
     if ($this->form_validation->run() == FALSE) {
         $this->form_validation->set_error_delimiters('', '');
         $data['code'] = '1010';
         $error['name'] = form_error('name');
         $error['info'] = form_error('info');
         $data['msg'] = $this->lang->line('error_msg');
         $data['error'] = $error;
         echo json_encode($data);
         exit;
     }
     $error = array();
     if ($post['id']) {
         $where = array('name' => trim($post['name']), 'id !=' => $post['id']);
         if ($this->product_brand->exist($where)) {
             $error['name'] = '名称已存在';
         }
     } else {
         $where = array('name' => trim($post['name']));
         if ($this->product_brand->exist($where)) {
             $error['name'] = '名称已存在';
         }
     }
     if (!empty($error)) {
         echo json_encode(array('code' => '1010', 'msg' => $this->lang->line('error_msg'), 'error' => $error));
         exit;
     }
     $row = array('name' => trim($post['name']), 'info' => trim($post['info']), 'product_cate_id' => trim($post['product_cate_id']));
     if ($post['id']) {
         if (!$this->product_brand->update($row, $post['id'])) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('update_fail'));
         }
         $id = $post['id'];
     } else {
         if (!($id = $this->product_brand->insert($row))) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('add_fail'));
         }
     }
     if ($data['code'] == '1000') {
         $data['goto'] = 'admin/product_brands';
         //处理图片
         if ($post['link_pic_path'] && is_file(upload_folder('temp') . DIRECTORY_SEPARATOR . $post['link_pic_path'])) {
             $target = upload_folder('product_brand') . DIRECTORY_SEPARATOR . file_save_dir($id);
             create_folder($target);
             $config['image_library'] = 'gd2';
             $config['source_image'] = upload_folder('temp') . DIRECTORY_SEPARATOR . $post['link_pic_path'];
             $config['create_thumb'] = false;
             $config['maintain_ratio'] = TRUE;
             $config['new_image'] = $target . DIRECTORY_SEPARATOR . file_save_name($id) . '.png';
             $config['width'] = 120;
             $config['height'] = 80;
             $this->load->library('image_lib', $config);
             $this->image_lib->resize();
             @unlink($config['source_image']);
         }
     }
     echo json_encode($data);
 }
예제 #6
0
파일: users.php 프로젝트: JokeLook/one
 /**
  * 上传用户头像
  * 
  */
 public function upload_pic()
 {
     $post = $this->input->post();
     $id = $this->auth->user_id();
     $data = array('code' => '1000', 'msg' => '');
     if (empty($post) && !$id) {
         show_error('参数错误');
     }
     //处理图片
     if ($post['user_pic_path'] && is_file(upload_folder('temp') . DIRECTORY_SEPARATOR . $post['user_pic_path'])) {
         $target = upload_folder('user') . DIRECTORY_SEPARATOR . file_save_dir($id);
         create_folder($target);
         $config['image_library'] = 'gd2';
         $config['source_image'] = upload_folder('temp') . DIRECTORY_SEPARATOR . $post['user_pic_path'];
         $config['create_thumb'] = false;
         $config['maintain_ratio'] = TRUE;
         $config['new_image'] = $target . DIRECTORY_SEPARATOR . file_save_name($id) . '.png';
         $config['width'] = 100;
         $config['height'] = 100;
         $this->load->library('image_lib', $config);
         $this->image_lib->resize();
         // $config['new_image'] = $target.DIRECTORY_SEPARATOR.file_save_name($id).'_small.png';
         // $config['width'] = 50;
         // $config['height'] = 50;
         // $this->load->library('image_lib', $config);
         // $this->image_lib->resize();
         @unlink($config['source_image']);
     } else {
         $data['code'] = '1001';
         $data['msg'] = '上传图片失败';
     }
     echo json_encode($data);
 }
예제 #7
0
파일: function.php 프로젝트: ivrm/mbgdorgen
function upload_tpl_folder_to_host()
{
    global $tpl_folder, $ftp_con, $ftp_dir, $id_task;
    //Папка с дополнительными файлами шаблона
    $folder_to_upload = 'data/tpl/' . $tpl_folder . '/i';
    //Если  она есть, то:
    if (is_dir($folder_to_upload)) {
        //Создаем папку 'i' на хосте
        if ($ftp_dir == '') {
            $mk_dir = @ftp_mkdir($ftp_con, 'i');
        } else {
            $mk_dir = @ftp_mkdir($ftp_con, $ftp_dir . '/i');
        }
        if (!$mk_dir) {
            echo "невозможно создать папку 'i' на хосте<br>";
        }
        //Заливаем файлы из папки 'i' шаблона, на хост
        $upload_images = upload_folder($folder_to_upload, 'i');
        if (!$upload_images) {
            set_status('dorgen_tasks', $id_task, 'dor_status', 'error');
            exit;
        }
    }
}
예제 #8
0
파일: products.php 프로젝트: JokeLook/one
 public function update()
 {
     $this->auth->check_login_json();
     $post = $this->input->post();
     if (empty($post)) {
         show_error('参数错误');
     }
     $data = array('code' => '1000', 'msg' => '');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('pcode', ' ', 'max_length[20]');
     $this->form_validation->set_rules('name', ' ', 'required|max_length[50]');
     $this->form_validation->set_rules('price', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('best_price', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('amount', ' ', 'integer|max_length[8]');
     $this->form_validation->set_rules('unit', ' ', 'max_length[30]');
     $this->form_validation->set_rules('weight', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('min_num', ' ', 'integer|max_length[11]');
     $this->form_validation->set_rules('score', ' ', 'integer|max_length[11]');
     $this->form_validation->set_rules('status', ' ', 'integer');
     $this->form_validation->set_rules('recommend', ' ', 'integer');
     $this->form_validation->set_rules('specials', ' ', 'integer');
     $this->form_validation->set_rules('hot', ' ', 'integer');
     $this->form_validation->set_rules('allow_comment', ' ', 'integer');
     $this->form_validation->set_rules('show_home', ' ', 'integer');
     $this->form_validation->set_rules('handpick', ' ', 'integer');
     if ($this->form_validation->run() == FALSE) {
         $this->form_validation->set_error_delimiters('', '');
         $data['code'] = '1010';
         $error['pcode'] = form_error('pcode');
         $error['name'] = form_error('name');
         $error['price'] = form_error('price');
         $error['best_price'] = form_error('best_price');
         $error['amount'] = form_error('amount');
         $error['unit'] = form_error('unit');
         $error['weight'] = form_error('weight');
         $error['min_num'] = form_error('min_num');
         $error['score'] = form_error('score');
         $error['status'] = form_error('status');
         $error['recommend'] = form_error('recommend');
         $error['specials'] = form_error('specials');
         $error['hot'] = form_error('hot');
         $error['allow_comment'] = form_error('allow_comment');
         $error['show_home'] = form_error('show_home');
         $error['handpick'] = form_error('handpick');
         $data['msg'] = $this->lang->line('error_msg');
         $data['error'] = $error;
         echo json_encode($data);
         exit;
     }
     $error = array();
     if ($post['id']) {
         if ($post['pcode']) {
             $where = array('code' => $post['pcode'], 'id !=' => $post['id']);
             if ($this->product->exist($where)) {
                 $error['pcode'] = '编码已存在';
             }
         }
         $where = array('name' => $post['name'], 'id !=' => $post['id']);
         if ($this->product->exist($where)) {
             $error['name'] = '名称已存在';
         }
     } else {
         if ($post['pcode']) {
             $where = array('code' => $post['pcode']);
             if ($this->product->exist($where)) {
                 $error['pcode'] = '编码已存在';
             }
         }
         $where = array('name' => $post['name']);
         if ($this->product->exist($where)) {
             $error['name'] = '名称已存在';
         }
     }
     if (!empty($error)) {
         echo json_encode(array('code' => '1010', 'msg' => $this->lang->line('error_msg'), 'error' => $error));
         exit;
     }
     $row = array('code' => $post['pcode'], 'name' => $post['name'], 'price' => $post['price'] ? $post['price'] : 0, 'best_price' => $post['best_price'] ? $post['best_price'] : 0, 'amount' => $post['amount'] ? $post['amount'] : 0, 'type_id' => $post['type_id'], 'cate_id' => $post['cate'], 'brand_id' => $post['brand_id'], 'unit' => $post['unit'], 'weight' => isset($post['weight']) ? floor($post['weight']) : 0, 'min_num' => isset($post['min_num']) ? intval($post['min_num']) : 0, 'score' => isset($post['score']) ? intval($post['score']) : 0, 'info' => $post['info'], 'promise' => $post['promise'], 'status' => isset($post['status']) ? round($post['status'], 2) : 0, 'recommend' => isset($post['recommend']) ? intval($post['recommend']) : 0, 'specials' => isset($post['specials']) ? $post['specials'] : 0, 'hot' => isset($post['hot']) ? intval($post['hot']) : 0, 'allow_comment' => isset($post['allow_comment']) ? intval($post['allow_comment']) : 0, 'show_home' => isset($post['show_home']) ? intval($post['show_home']) : 0, 'handpick' => isset($post['handpick']) ? intval($post['handpick']) : 0);
     if ($post['id']) {
         if (!$this->product->update($row, $post['id'])) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('update_fail'));
         }
         $id = $post['id'];
         $this->product_category_map->delete_by_product($id);
     } else {
         if (!($id = $this->product->insert($row))) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('add_fail'));
         }
     }
     if ($data['code'] == '1000') {
         if (isset($post['cate_id']) && $post['cate_id'] && is_array($post['cate_id']) && !empty($post['cate_id'])) {
             foreach ($post['cate_id'] as $key => $value) {
                 $this->product_category_map->insert(array('product_id' => $id, 'category_id' => $value));
             }
         }
         $data['goto'] = 'admin/products';
         //处理图片
         $this->load->library('image_lib');
         $target = upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id);
         create_folder($target);
         $tmp_folder = upload_folder('temp');
         $target_name = file_save_name($id);
         $unlink = array();
         for ($i = 1; $i <= 5; $i++) {
             if ($post['pro_pic_path_' . $i] && is_file($tmp_folder . DIRECTORY_SEPARATOR . $post['pro_pic_path_' . $i])) {
                 $config['image_library'] = 'gd2';
                 $config['source_image'] = $tmp_folder . DIRECTORY_SEPARATOR . $post['pro_pic_path_' . $i];
                 $config['create_thumb'] = false;
                 $config['maintain_ratio'] = TRUE;
                 $config['new_image'] = $target . DIRECTORY_SEPARATOR . $target_name . '_' . $i . '.png';
                 $config['width'] = 800;
                 $config['height'] = 600;
                 $this->image_lib->initialize($config);
                 $this->image_lib->resize();
                 $config['new_image'] = $target . DIRECTORY_SEPARATOR . $target_name . '_' . $i . '_thumb.png';
                 $config['width'] = 200;
                 $config['height'] = 150;
                 $this->image_lib->initialize($config);
                 $this->image_lib->resize();
                 $unlink[] = $config['source_image'];
             }
         }
         if (!empty($unlink)) {
             foreach ($unlink as $key => $value) {
                 @unlink($value);
             }
         }
     }
     echo json_encode($data);
 }