|
@@ -295,7 +295,7 @@ class FileManager extends Base
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
$file = $this->request->file('upload_file');
|
|
|
- halt($file);
|
|
|
+
|
|
|
if ($file) {
|
|
|
try {
|
|
|
validate(
|
|
@@ -313,50 +313,13 @@ class FileManager extends Base
|
|
|
]
|
|
|
)->check(['file' => $file]);
|
|
|
|
|
|
- $urlpath = Config::get('filesystem.disks.public.url');
|
|
|
-
|
|
|
- $username = $this->getSysUser()->username;
|
|
|
-
|
|
|
- $savename = str_replace('\\', '/', $file->hashName());
|
|
|
-
|
|
|
- $originalName = $file->getOriginalName();
|
|
|
-
|
|
|
- $thumbname = "";
|
|
|
-
|
|
|
- if ($thumb == true) {
|
|
|
- $image = Image::open($file);
|
|
|
-
|
|
|
- $image->thumb($width, $height, 1);
|
|
|
-
|
|
|
- $ext = $file->extension();
|
|
|
-
|
|
|
- if ($original == true) {
|
|
|
- \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
-
|
|
|
- $thumbname = str_replace('.' . $ext, '', $savename) . $this->t_suffix . '.' . $ext;
|
|
|
-
|
|
|
- $savepath = str_replace('\\', '/', Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
-
|
|
|
- $image->save($savepath);
|
|
|
-
|
|
|
- FileManagerModel::saveFileInfo($savepath, $thumbname, $originalName, $id, $cjid, $username);
|
|
|
-
|
|
|
- $thumbname = $urlpath . '/' . $thumbname;
|
|
|
- } else {
|
|
|
- $image->save(Config::get('filesystem.disks.public.root') . '/' . $savename);
|
|
|
- }
|
|
|
- } else {
|
|
|
- \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
- }
|
|
|
-
|
|
|
- $fileinfo = FileManagerModel::saveFileInfo($file, $savename, $originalName, $id, $cjid, $username);
|
|
|
+ $result = $this->dealUploadImg($file, $thumb, $width, $height, $original, $id, $cjid);
|
|
|
|
|
|
return json([
|
|
|
'code' => 0,
|
|
|
'img_id' => $img_id,
|
|
|
- 'picname' => $fileinfo->filepath,
|
|
|
- 'thumb' => $thumbname
|
|
|
-
|
|
|
+ 'picname' => $result['picname'],
|
|
|
+ 'thumb' => $result['thumbname']
|
|
|
]);
|
|
|
} catch (ValidateException $e) {
|
|
|
$this->error($e->getMessage());
|
|
@@ -389,49 +352,13 @@ class FileManager extends Base
|
|
|
try {
|
|
|
$file = FileUtils::downloadUrlImg($urlImg);
|
|
|
|
|
|
- $urlpath = Config::get('filesystem.disks.public.url');
|
|
|
-
|
|
|
- $username = $this->getSysUser()->username;
|
|
|
-
|
|
|
- $savename = str_replace('\\', '/', $file->hashName());
|
|
|
-
|
|
|
- $originalName = $file->getOriginalName();
|
|
|
-
|
|
|
- $thumbname = "";
|
|
|
+ $result = $this->dealUploadImg($file, $thumb, $width, $height, $original, $id, $cjid);
|
|
|
|
|
|
- if ($thumb == true) {
|
|
|
- $image = Image::open($file);
|
|
|
-
|
|
|
- $image->thumb($width, $height, 1);
|
|
|
-
|
|
|
- $ext = $file->extension();
|
|
|
-
|
|
|
- if ($original == true) {
|
|
|
- \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
-
|
|
|
- $thumbname = str_replace('.' . $ext, '', $savename) . $this->t_suffix . '.' . $ext;
|
|
|
-
|
|
|
- $savepath = str_replace('\\', '/', Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
-
|
|
|
- $image->save($savepath);
|
|
|
-
|
|
|
- FileManagerModel::saveFileInfo($savepath, $thumbname, $originalName, $id, $cjid, $username);
|
|
|
-
|
|
|
- $thumbname = $urlpath . '/' . $thumbname;
|
|
|
- } else {
|
|
|
- $image->save(Config::get('filesystem.disks.public.root') . '/' . $savename);
|
|
|
- }
|
|
|
- } else {
|
|
|
- \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
- }
|
|
|
- $fileinfo = FileManagerModel::saveFileInfo($file, $savename, $originalName, $id, $cjid, $username);
|
|
|
-
|
|
|
return json([
|
|
|
'code' => 0,
|
|
|
'img_id' => $img_id,
|
|
|
- 'picname' => $fileinfo->filepath,
|
|
|
- 'thumb' => $thumbname
|
|
|
-
|
|
|
+ 'picname' => $result['picname'],
|
|
|
+ 'thumb' => $result['thumbname']
|
|
|
]);
|
|
|
} catch (\think\exception\ValidateException $e) {
|
|
|
$this->error($e->getMessage());
|
|
@@ -602,38 +529,49 @@ class FileManager extends Base
|
|
|
/**
|
|
|
* 处理上传的图片
|
|
|
*/
|
|
|
- protected function dealUploadImg(File $file, $thumb, $width, $height, $overwrite, $id = 0, $cjid = 0)
|
|
|
+ protected function dealUploadImg(UploadedFile $file, $thumb, $width, $height, $original, $id, $cjid): array
|
|
|
{
|
|
|
- $savename = $file->hashName();
|
|
|
+ $urlpath = Config::get('filesystem.disks.public.url');
|
|
|
+
|
|
|
+ $username = $this->getSysUser()->username;
|
|
|
+
|
|
|
+ $savename = str_replace('\\', '/', $file->hashName());
|
|
|
+
|
|
|
+ $originalName = $file->getOriginalName();
|
|
|
+
|
|
|
+ $thumbname = "";
|
|
|
|
|
|
if ($thumb == true) {
|
|
|
$image = Image::open($file);
|
|
|
|
|
|
- if ($overwrite == true) {
|
|
|
- $image->thumb($width, $height, 1);
|
|
|
-
|
|
|
- $realPath = Config::get('filesystem.disks.public.root') . '/' . $savename;
|
|
|
+ $image->thumb($width, $height, 1);
|
|
|
|
|
|
- $image->save($realPath);
|
|
|
- } else {
|
|
|
+ $ext = $file->extension();
|
|
|
+
|
|
|
+ if ($original == true) {
|
|
|
+ \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
|
|
|
- $ext = $file->extension();
|
|
|
+ $thumbname = str_replace('.' . $ext, '', $savename) . $this->t_suffix . '.' . $ext;
|
|
|
+
|
|
|
+ $savepath = str_replace('\\', '/', Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
|
|
|
- $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $savename)) . $this->t_suffix . '.' . $ext;
|
|
|
+ $image->save($savepath);
|
|
|
|
|
|
- $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
- }
|
|
|
+ FileManagerModel::saveFileInfo($savepath, $thumbname, $originalName, $id, $cjid, $username);
|
|
|
|
|
|
- unset($image);
|
|
|
+ $thumbname = $urlpath . '/' . $thumbname;
|
|
|
+ } else {
|
|
|
+ $image->save(Config::get('filesystem.disks.public.root') . '/' . $savename);
|
|
|
+ }
|
|
|
} else {
|
|
|
- $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
+ \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
}
|
|
|
|
|
|
- $picture_url = Config::get('filesystem.disks.public.url') . '/';
|
|
|
+ $fileinfo = FileManagerModel::saveFileInfo($file, $savename, $originalName, $id, $cjid, $username);
|
|
|
|
|
|
return [
|
|
|
- 'picname' => $picture_url . str_replace('\\', '/', $savename),
|
|
|
- 'thumbname' => $thumbname ? $picture_url . $thumbname : ""
|
|
|
+ 'picname' => $fileinfo->filepath,
|
|
|
+ 'thumbname' => $thumbname,
|
|
|
];
|
|
|
}
|
|
|
}
|