Esempio n. 1
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;
 }