Ejemplo n.º 1
0
}
$field = $uploadFile[0]['path'];
//上传成功文件物理路径
$info = pathinfo($field);
$fileData = array();
$fileData[0]['path'] = $field;
//上传后的大图
$fileData[0]['url'] = __ROOT__ . '/' . $field;
//上传后的大图URL
$json = array();
$json['state'] = $state;
$json['fid'] = md5($field);
if (getimagesize($field)) {
    //图片裁切处理
    $img = new image();
    $img->water($field);
    $json['thumb']['file'] = __ROOT__ . '/' . $field;
    $json['thumb']['w'] = $display_width;
    $json['thumb']['h'] = $display_height;
}
if ($imagesize && getimagesize($field)) {
    //图片裁切处理
    $n = 1;
    for ($i = 0; $i < count($size); $i += 2) {
        $toFile = $info['filename'] . $n . '.' . $info['extension'];
        $img->thumb($field, $toFile, '', $size[$i], $size[$i + 1], $thumb_type);
        $fileData[$n]['path'] = $info['dirname'] . '/' . $toFile;
        $n++;
    }
}
$json['file'] = $fileData;
Ejemplo n.º 2
0
 /**
  * 储存文件
  * @param string $file 储存的文件
  * @return boolean
  */
 private function save($file)
 {
     $is_img = 0;
     $uploadFileName = mt_rand(1, 9999) . time() . "." . $file['ext'];
     $filePath = $this->path . $uploadFileName;
     if (in_array(strtolower($file['ext']), array("jpeg", "jpg", "bmp", "gif", "png")) && getimagesize($file['tmp_name'])) {
         $imgDir = C("UPLOAD_IMG_DIR") ? C("UPLOAD_IMG_DIR") . "/" : "";
         $filePath = $this->path . $imgDir . $uploadFileName;
         if (!$this->checkDir($this->path . $imgDir)) {
             $this->error = '图片上传目录创建失败或不可写';
             return false;
         }
         $is_img = 1;
     }
     if (!move_uploaded_file($file['tmp_name'], $filePath)) {
         $this->error('移动临时文件失败');
         return false;
     }
     if (!$is_img) {
         $filePath = ltrim(str_replace(ROOT_PATH, '', $filePath), '/');
         $arr = array("path" => $filePath, 'fieldname' => $file['fieldname'], 'image' => 0);
     } else {
         //处理图像类型文件
         $img = new image();
         $imgInfo = getimagesize($filePath);
         //对原图进行缩放
         if (C("UPLOAD_IMG_RESIZE_ON") && ($imgInfo[0] > C("UPLOAD_IMG_MAX_WIDTH") || $imgInfo[1] > C("UPLOAD_IMG_MAX_HEIGHT"))) {
             $img->thumb($filePath, $uploadFileName, C("UPLOAD_IMG_MAX_WIDTH"), C("UPLOAD_IMG_MAX_HEIGHT"), 5, $this->path);
         }
         //生成缩略图
         if ($this->thumbOn) {
             $args = array();
             if (empty($this->thumb)) {
                 array_unshift($args, $filePath);
             } else {
                 array_unshift($args, $filePath, "", "");
                 $args = array_merge($args, $this->thumb);
             }
             $thumbFile = call_user_func_array(array($img, "thumb"), $args);
         }
         //加水印
         if ($this->waterMarkOn) {
             $img->water($filePath);
         }
         $filePath = trim(str_replace(ROOT_PATH, '', $filePath), '/');
         if ($this->thumbOn) {
             $thumbFile = trim(str_replace(ROOT_PATH, '', $thumbFile), '/');
             $arr = array("path" => $filePath, "thumb" => $thumbFile, 'fieldname' => $file['fieldname'], 'image' => 1);
         } else {
             $arr = array("path" => $filePath, 'fieldname' => $file['fieldname'], 'image' => 1);
         }
     }
     $arr['path'] = preg_replace('@\\./@', '', $arr['path']);
     //上传时间
     $arr['uptime'] = time();
     $info = pathinfo($filePath);
     $arr['fieldname'] = $file['fieldname'];
     $arr['basename'] = $info['basename'];
     $arr['filename'] = $info['filename'];
     $arr['size'] = $file['size'];
     $arr['ext'] = $file['ext'];
     $dir = str_ireplace("\\", "/", dirname($arr['path']));
     $arr['dir'] = substr($dir, "-1") == "/" ? $dir : $dir . "/";
     return $arr;
 }
Ejemplo n.º 3
0
    /**
     * 储存文件
     * @param string $file 储存的文件
     * @return boolean
     */
    private function save($file)
    {
        $is_img = 0;
        $uploadFileName = mt_rand(1, 9999) . time() . "." . $file['ext'];
        $filePath = $this->path . $uploadFileName;
        if (in_array(strtolower($file ['ext']), array("jpeg", "jpg", "bmp", "gif", "png")) && getimagesize($file ['tmp_name'])) {
            $imgDir = C("UPLOAD_IMG_DIR") ? C("UPLOAD_IMG_DIR") . "/" : "";
            $filePath = $this->path . $imgDir . $uploadFileName;
            if (!$this->checkDir($this->path . $imgDir)) {
                $this->error = L("upload_save_error1");
                return false;
            }
            $is_img = 1;
        }
        if (!move_uploaded_file($file ['tmp_name'], $filePath)) {
            $this->error(L("upload_save_error2"));
            return false;
        }

        if (!$is_img) {
            $filePath = ltrim(str_replace(PATH_ROOT, '', $filePath), '/');
            return array("path" => $filePath, 'fieldname' => $file['fieldname']);
        }
        //处理图像类型文件
        $img = new image ();
        //对原图进行缩放
        if (C("UPLOAD_IMG_RESIZE_ON")) {
            $img->thumb($filePath, $uploadFileName, '', C("UPLOAD_IMG_MAX_WIDTH"), C("UPLOAD_IMG_MAX_HEIGHT"), 5);
        }
        //生成缩略图
        if ($this->thumbOn) {
            $args = array();
            if (empty($this->thumb)) {
                array_unshift($args, $filePath);
            } else {
                array_unshift($args, $filePath, "", "");
                $args = array_merge($args, $this->thumb);
            }
            $thumbFile = call_user_func_array(array($img, "thumb"), $args);
        }
        //加水印
        if ($this->waterMarkOn) {
            $img->water($filePath);
        }
        $filePath = ltrim(str_replace(ROOT_PATH, '', $filePath), '/');
        $arr = array();
        if ($this->thumbOn) {
            $thumbFile = ltrim(str_replace(PATH_ROOT, '', $thumbFile), '/');
            $arr = array("path" => $filePath, "thumb" => $thumbFile);
        } else {
            $arr = array("path" => $filePath);
        }
        return array_merge($arr, $file);
    }