params['frontEndBaseUrl']; $fullPath = $baseUrl.$path; if ('min' == $style) { $fileArr = explode('.', $path); $end = array_pop($fileArr); $newPath = implode('.', $fileArr); $fullPath = $baseUrl.$newPath.'_min.'.$end; } return $fullPath; } /** * @param $licensePic * @param $fileTypePath * @return string */ public static function mvUploadImage($licensePic, $uuid, $fileTypePath = '') { $dir = Yii::getAlias('@site') . "/tmp"; $tmpFilePath = $dir.'/'.$licensePic; $fileArr = explode('.', $licensePic); $minFileName = $fileArr[0].'_min'.'.'.end($fileArr); $tmpMinFilePath = $dir.'/'.$minFileName; $desPathFile = self::genImagePath($uuid, $fileTypePath); $aimPath = Yii::getAlias('@site')."/".$desPathFile .$licensePic; FileUtil::moveFile($tmpFilePath, $aimPath,true); $aimTPath = Yii::getAlias('@site')."/".$desPathFile .$minFileName; FileUtil::moveFile($tmpMinFilePath, $aimTPath,true); return [$desPathFile, $licensePic, $minFileName]; } /** * @param $uuid * @param string $fileTypePath * @return string */ public static function genImagePath($uuid, $fileTypePath = '') { if (empty($fileTypePath)) { $catPath = self::$MAINTENANCE_PATH; } else { $catPath = $fileTypePath; } $desPathFile = "upload/".$catPath.$uuid.'/'; return $desPathFile; } private static function _imageCreateFromPath($imgPath) { list($width, $height, $type, $attr) = getimagesize($imgPath); switch ($type) { case 3: // png return imagecreatefrompng($imgPath); case 2: // jpeg return imagecreatefromjpeg($imgPath); default: return null; } } /** * 上传到服务器临时文件区 * @param $fileInfo $_FILE['file'] * @return array */ public static function uploadImg($fileInfo) { $dir = Yii::getAlias('@site') . "/tmp"; $fileArr = explode('.', $fileInfo['name']); $tt = time(); $filename = 'auto_'.$tt.md5($fileInfo['name']).'.'.end($fileArr); $minFileName = 'auto_'.$tt.md5($fileInfo['name']).'_min'.'.'.end($fileArr); $saveFilePath = $dir.'/'.$filename; move_uploaded_file($fileInfo['tmp_name'], $saveFilePath); $tmpUrl = $tmpMinFile = 'tmp/'.$filename; $imgSource = self::_imageCreateFromPath($saveFilePath); if ($imgSource) { ImageUtils::resizeImage($imgSource, 100, 100, $dir.'/'.$minFileName); $tmpMinFile = 'tmp/'.$minFileName; } return [$filename, $minFileName, $tmpUrl, $tmpMinFile]; } }