Пример #1
0
 /**
  * 重命名文件
  *
  * @return bool
  * @author weizhifeng
  **/
 protected function act_rename()
 {
     if (!$this->check_time_out()) {
         $this->time_error_msg(Kohana::lang('o_kc.time_out'));
     }
     if ($this->config['readonly'] || !isset($this->post['file']) || !isset($this->post['new_name']) || !isset($this->post['file_id']) || !isset($this->post['dir_id'])) {
         $this->error_msg(Kohana::lang('o_kc.file_not_exist'));
     }
     $file_id = (int) $this->post['file_id'];
     $new_name = trim($this->post['new_name']);
     $old_name = trim($this->post['file']);
     $dir_id = (int) $this->post['dir_id'];
     if (!strlen($new_name)) {
         $this->error_msg(Kohana::lang('o_kc.enter_new_file_name'));
     }
     if (preg_match('/[\\/\\\\]/s', $new_name)) {
         $this->error_msg(Kohana::lang('file_name_have_unallow_char'));
     }
     if (substr($new_name, 0, 1) == ".") {
         $this->error_msg(Kohana::lang('o_kc.file_name_begin_with'));
     }
     if (strlen($new_name) >= 254) {
         $this->error_msg(Kohana::lang('o_kc.file_name_too_long'));
     }
     // 文件检查
     if ($new_name != $old_name and $this->file_exists(1, $dir_id, $new_name)) {
         $this->error_msg(Kohana::lang('o_kc.file_name_exist'));
     }
     $ext = kc_file::get_extension($new_name);
     if (!$this->validate_extension($ext, $this->type)) {
         $this->error_msg(Kohana::lang('o_kc.denied_file_extension'));
     }
     $data = array('image_name' => $new_name, 'date_upd' => date('Y-m-d H:i:s'));
     if ($this->kc_image->update($file_id, $data) === FALSE) {
         $this->error_msg(Kohana::lang('o_kc.file_rename_failed'));
     }
     $this->template->content = new View("kc_rename");
 }
Пример #2
0
 /**
  * 上传文件检查
  *
  * @return mixed
  * @author weizhifeng
  **/
 protected function check_uploaded_file()
 {
     $config =& $this->config;
     $file =& $this->file;
     if (!is_array($file) || !isset($file['name'])) {
         return Kohana::lang('o_kc.unknown_error');
     }
     $extension = kc_file::get_extension($file['name']);
     $typePatt = strtolower(kc_text::clear_whitespaces($this->types[$this->type]));
     // 上传错误处理
     if ($file['error']) {
         switch ($file['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 //return Kohana::lang('o_kc.upload_exceed_size', ini_get('upload_max_filesize'));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 //return Kohana::lang('o_kc.upload_exceed_size', $this->get['MAX_FILE_SIZE']);
                 break;
             case UPLOAD_ERR_PARTIAL:
                 return Kohana::lang('o_kc.file_part_upload');
                 break;
             case UPLOAD_ERR_NO_FILE:
                 return Kohana::lang('o_kc.no_file_upload');
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 return Kohana::lang('o_kc.miss_temp_folder');
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 return Kohana::lang('o_kc.fail_write_file');
                 break;
             default:
                 return Kohana::lang('o_kc.unknown_error');
                 break;
         }
         // 隐藏文件处理
     } elseif (substr($file['name'], 0, 1) == ".") {
         return Kohana::lang('o_kc.file_name_begin_with');
         // 扩展名校验
     } elseif (!$this->validate_extension($extension, $this->type)) {
         return Kohana::lang('o_kc.denied_file_extension');
     }
     return TRUE;
 }