Ejemplo n.º 1
0
 /**
  * 编辑分类
  * @param  array  $set
  * @throws Exception
  */
 public function cateEdit(array $set)
 {
     if (isset($set['cate_id'])) {
         $cateId = (int) $set['cate_id'];
         $where = $this->db->quoteInto('cate.cate_id=?', $cateId);
         if (!$this->cateExists($where)) {
             throw new Exception('指定的分类不存在');
         }
     }
     $validator = $this->_validateCate($set);
     if (!$validator->isValid()) {
         throw new Exception($validator->getMessage());
     }
     $set = array('cate_name' => htmlspecialchars($set['cate_name']), 'filepath' => strip_tags($set['filepath']), 'description' => htmlspecialchars($set['description']), 'allow_upload' => (int) @$set['allow_upload'], 'allow_delete' => (int) @$set['allow_delete']);
     $where = $this->db->quoteInto('cate.cate_name=?', $set['cate_name']);
     if ($this->cateExists($where)) {
         throw new Exception("指定的分类名称 '{$set['cate_name']}' 已经存在");
     }
     $where = $this->db->quoteInto('cate.filepath=?', $set['filepath']);
     if ($this->cateExists($where)) {
         throw new Exception("指定的路径 '{$set['filepath']}' 已经被占用");
     }
     $abspath = $this->fileBasePath . "/" . $set['filepath'];
     if (!is_dir($abspath)) {
         $mk = YUN_Io::mkdir($abspath);
         if ($mk === false) {
             throw new Exception("无法创建分类目录 '{$set['filepath']}'");
         }
     }
     $where = $this->db->quoteInto('cate_id=?', $cateId);
     $this->db->update('file_category', $set, $where);
 }
Ejemplo n.º 2
0
 /**
  * 保存上传的文件
  *
  * @example YUN_File_Upload::save($_FILES['fieldname']);
  *
  * @param  array   $data      POST 的文件上传数据
  * @param  string  $saveName
  * @param  string  $savePath
  * @return boolean
  */
 public function save(array $data, $saveName = null, $savePath = null)
 {
     if (!$this->isPostFile($data)) {
         $this->_message = '无效的 POST 数据';
         return false;
     }
     if (isset($data['error']) && $data['error'] != 0) {
         $this->_message = $this->getError($data['error']);
         return false;
     }
     if (!$this->isAllowExtension($data['name'])) {
         $this->_message = '禁止上传该类型的文件';
         return false;
     }
     if (!$this->isAllowSize($data['size'])) {
         $this->_message = "文件大小超出服务器限定的值 ({$this->_config['maxSize']} Kb)";
         return false;
     }
     empty($savePath) && ($savePath = $this->_config['savePath']);
     $mkpath = YUN_Io::mkdir($savePath);
     if ($mkpath === false) {
         $this->_message = "无法创建文件上传目录 '{$savePath}'";
         return false;
     }
     $extension = $this->getExtension($data['name']);
     if (empty($saveName)) {
         $saveName = $this->_config['rename'] ? str_replace('.', '', microtime(true)) . ".{$extension}" : $data['name'];
     } else {
         $saveName = strtolower($saveName);
         // 兼容 win 平台
     }
     $saveFilename = YUN_Io::strip("{$savePath}/{$saveName}");
     if (!@move_uploaded_file($data['tmp_name'], $saveFilename)) {
         $this->_message = '无法从临时目录复制上传文件';
         return false;
     }
     $this->_result = array('filename' => $data['name'], 'filesize' => $data['size'], 'filetype' => $data['type'], 'extension' => $extension, 'savename' => $saveFilename);
     return true;
 }