Ejemplo n.º 1
0
 /**
  * 上传一个文件
  * 
  * @param $file 对应html中的一个html file控件
  * @param $path 存储路径
  * @param $seed 分级路径的种子,种子将被MD5后,从左至右每两位作为一级路径
  * @param $hashLevel 文件路径层级,将
  * @return unknown_type
  */
 public static function upload($file, $path, $allowType = '', $rename = true, $level = 0, $seed = null)
 {
     $ext = strtolower(self::getExt($file['name']));
     if (!empty($allowType) && strstr($allowType, $ext) === false) {
         throw new Hi_Tool_Exception("不上传允许的文件格式[{$ext}]");
     }
     if ($rename) {
         $name = time() . '_' . rand(10000, 99999) . '.' . $ext;
     } else {
         $name = $file['name'];
     }
     if ($seed) {
         $name = $seed . '_' . $name;
     }
     $path = Hi_Tool_Dir::standard($path);
     $level = intval($level);
     if ($level != 0) {
         $path = Hi_Tool_Dir::createByHash($path, 2, $seed);
     } else {
         Hi_Tool_Dir::create($path);
     }
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     $fp = $path . $name;
     copy($file['tmp_name'], $fp);
     return $fp;
 }