Ejemplo n.º 1
0
 /**
  * 删除分类
  * @param  integer  $cateId
  * @throws Exception
  */
 public function cateDel($cateId)
 {
     $where = $this->db->quoteInto('cate_id=?', $cateId);
     $cateInfo = $this->cateInfoSql($where);
     if (empty($cateInfo)) {
         throw new Exception('指定的分类不存在');
     }
     if (!$cateInfo['allow_delete']) {
         throw new Exception('该分类被设置为禁止删除');
     }
     $abspath = $this->fileBasePath . "/" . $cateInfo['filepath'];
     if (is_dir($abspath)) {
         $files = YUN_Io::scan($abspath);
         if (!empty($files)) {
             throw new Exception('分类目录不为空,无法删除');
         }
         rmdir($abspath);
     }
     $this->db->delete('file_category', $where);
     $this->db->delete('file', $where);
 }
Ejemplo n.º 2
0
 /**
  * 生成图像
  *
  * @param  string  $phrase
  * @return resource
  * @throws Exception
  */
 public function generateImage($phrase = null)
 {
     null == $phrase && ($phrase = $this->generatePhrase());
     extract($this->_options);
     //解出参数到变量
     $image = $this->_createImage();
     //创建图像
     $defaultSize = min($width, $height * 2) / (strlen($phrase) + 1);
     $spacing = (int) ($width * 0.9 / strlen($phrase));
     empty($fonts) && ($fonts = YUN_Io::scan(strip($fontDir)));
     if (empty($fonts)) {
         throw new Exception('未找到任何有效的字体文件');
     }
     for ($i = 0, $strlen = strlen($phrase); $i < $strlen; $i++) {
         $font = $fontDir . '/' . $fonts[array_rand($fonts)];
         $color = imagecolorallocate($image, mt_rand(0, 160), mt_rand(0, 160), mt_rand(0, 160));
         $angle = mt_rand(-30, 30);
         $size = $defaultSize / 10 * mt_rand(12, 14);
         $box = imageftbbox($size, $angle, $font, $phrase[$i]);
         $x = $spacing / 4 + $i * $spacing + 2;
         $y = $height / 2 + ($box[2] - $box[5]) / 4;
         imagefttext($image, $size, $angle, $x, $y, $color, $font, $phrase[$i]);
     }
     $this->_image = $image;
     return $this->_image;
 }
Ejemplo n.º 3
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;
 }