Example #1
0
function gb2utf8($data)
{
    if (is_string($data) && $data != '') {
        if (is_gb2312($data)) {
            $data = iconv('gb2312', 'utf-8', $data);
        }
    } elseif (is_array($data)) {
        foreach ($data as $key => $value) {
            $data[$key] = gb2utf8($value);
        }
    }
    return $data;
}
Example #2
0
 function upload($path = '')
 {
     $path = trim($path, '/');
     $folder = $this->BasePath . $path;
     if (!is_dir($folder)) {
         if (is_gb2312($path)) {
             $path = iconv('gb2312', 'utf-8', $path);
         }
         throw new Exception("文件夹 '{$path}' 不存在。");
     }
     if (!file_exists('fileupload.class.php')) {
         throw new Exception("没找到文件'fileupload.class.php, 无法上传文件。");
     }
     require_once 'fileupload.class.php';
     $up = new FileUpload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $folder);
     $up->set("maxsize", 8 * 1024 * 1024);
     if (empty($this->allowType) || $this->allowType == '*') {
         $up->set("allowtype", explode(',', $this->allType));
     } else {
         $up->set("allowtype", explode(',', $this->allowType));
     }
     $up->set("israndname", false);
     if (!$up->upload("file")) {
         $errors = $up->getErrorMsg();
         if (is_array($errors)) {
             $errors = implode("\n", $errors);
         }
         throw new Exception($errors);
     } else {
         $filenames = $up->getFileName();
         if (is_string($filenames)) {
             $filenames[] = $filenames;
         }
         foreach ($filenames as $key => $value) {
             $filename = iconv('utf-8', 'gb2312', $value);
             if (true === @rename($folder . '/' . $value, $folder . '/' . $filename)) {
                 $filenames[$key] = $filename;
             }
         }
     }
     return $up->getFileName();
 }