public static function resize($image, $size) { self::init_img_info($image); $arg_length = func_num_args(); if ($arg_length == 1) { return false; } $arguments = func_get_args(); $cut = false; $last_arg = $arguments[$arg_length - 1]; $length = $arg_length - 1; if (is_bool($last_arg)) { if ($arg_length <= 2) { return false; } $length = $arg_length - 2; $cut = $last_arg; } $orig_width = self::$_img_width; $orig_height = self::$_img_height; $success = (int) 0; for ($i = 1; $i <= $length; $i++) { if (!is_array($arguments[$i])) { return false; } if ($orig_width <= $orig_height) { $according = $arguments[$i][0] / $orig_width; } else { $according = $arguments[$i][1] / $orig_height; } $width = $orig_width * $according; $height = $orig_height * $according; $target = isset($arguments[$i][2]) ? $arguments[$i][2] : ''; $result = self::resize_pic($image, $width, $height, $target); if ($cut == true && file_exists($target)) { $img_size_arr = getimagesize($target); $target_width = $arguments[$i][0]; $target_height = $arguments[$i][1]; $cut_x = $img_size_arr[0] < $target_width ? '0' : ($img_size_arr[0] - $target_width) / 2; $cut_y = $img_size_arr[1] < $target_height ? '0' : ($img_size_arr[1] - $target_height) / 2; self::cut_pic($target, $target_width, $target_height, $cut_x, $cut_y); } keke_glob_class::waterMark($target); $result == true && $success++; } return $success > 0 ? true : false; }
$upload = new keke_upload_class(S_ROOT . $pathDir, $fileFormat, $maxSize); $savename = $upload->run($filename, 1); if (!is_array($savename)) { $err = $msg = $savename; echo json_encode(array('err' => $err, 'msg' => $msg)); die; } else { $name = $savename[0]['name']; $path = $pathDir . $savename[0]['saveName']; if ($fileType == 'service') { $size_a = array(100, 100); $size_b = array(210, 210); $result = keke_img_class::resize($path, $size_a, $size_b, true); } if ($fileType != 'sys') { keke_glob_class::waterMark($path); } $savefilename = $savename[0]['name']; } } if (strtoupper(CHARSET) == 'GBK') { $savefilename = kekezu::utftogbk($savefilename); } $data = array(); $data['file_name'] = $savefilename; $data['save_name'] = $path; $data['uid'] = $gUid; $data['username'] = $gUsername; $data['obj_type'] = $objType; $data['task_id'] = $taskId; $data['work_id'] = $workId;
/** * 上传文件的主处理方法 * @return mixed */ private function upFile() { $file = $this->file = $_FILES[$this->fileField]; if (!$file) { $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND"); return; } if ($this->file['error']) { $this->stateInfo = $this->getStateInfo($file['error']); return; } else { if (!file_exists($file['tmp_name'])) { $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND"); return; } else { if (!is_uploaded_file($file['tmp_name'])) { $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE"); return; } } } $this->oriName = $file['name']; $this->fileSize = $file['size']; $this->fileType = $this->getFileExt(); $this->fullName = $this->getFullName(); $this->filePath = $this->getFilePath(); $this->fileName = $this->getFileName(); $dirname = dirname($this->filePath); //检查文件大小是否超出限制 if (!$this->checkSize()) { $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED"); return; } //检查是否不允许的文件格式 if (!$this->checkType()) { $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED"); return; } //创建目录失败 if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) { $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR"); return; } else { if (!is_writeable($dirname)) { $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE"); return; } } //移动文件 if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败 $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE"); } else { //移动成功 $this->stateInfo = $this->stateMap[0]; } //水印 keke_glob_class::waterMark($this->filePath); }
/** * 上传文件的主处理方法 * @return mixed */ private function upFile() { $file = $this->file = $_FILES[$this->fileField]; if (!$file) { $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND"); return; } if ($this->file['error']) { $this->stateInfo = $this->getStateInfo($file['error']); return; } else { if (!file_exists($file['tmp_name'])) { $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND"); return; } else { if (!is_uploaded_file($file['tmp_name'])) { $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE"); return; } } } $this->oriName = $file['name']; $this->fileSize = $file['size']; $this->fileType = $this->getFileExt(); $this->fullName = $this->getFullName(); $this->filePath = $this->getFilePath(); $this->fileName = $this->getFileName(); $dirname = dirname($this->filePath); //检查文件大小是否超出限制 if (!$this->checkSize()) { $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED"); return; } //检查是否不允许的文件格式 if (!$this->checkType()) { $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED"); return; } //创建目录失败 if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) { $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR"); return; } else { if (!is_writeable($dirname)) { $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE"); return; } } if (QN_UPLOAD_OPEN) { global $kekezu; //加载七牛类文件 $kekezu->include_qiniu_file(); $qn = new QiniuClass(); $ret = $qn->upload($this->oriName, $file["tmp_name"]); if (!$ret) { $this->stateInfo = $this->getStateInfo("ERROR_QINIU_CONFIG"); return false; } else { $url = $qn->download($ret['key']); $savefilename = $ret['key']; $urls = explode('?', $url); $path = $urls[0]; $this->fullName = $path; $this->stateInfo = $this->stateMap[0]; return; } } //移动文件 if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败 $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE"); } else { //移动成功 $this->stateInfo = $this->stateMap[0]; } //水印 keke_glob_class::waterMark($this->filePath); }