|
@@ -32,7 +32,7 @@ class FileManager extends Base
|
|
protected $width = 400; // 缩略图高度
|
|
protected $width = 400; // 缩略图高度
|
|
protected $height = 300;
|
|
protected $height = 300;
|
|
protected $storage_path = 'public/storage';
|
|
protected $storage_path = 'public/storage';
|
|
-
|
|
|
|
|
|
+
|
|
public function index()
|
|
public function index()
|
|
{
|
|
{
|
|
$param = $this->request->param();
|
|
$param = $this->request->param();
|
|
@@ -144,7 +144,7 @@ class FileManager extends Base
|
|
$fileinfo->hash_md5 = $file->md5();
|
|
$fileinfo->hash_md5 = $file->md5();
|
|
|
|
|
|
if (empty($activepath)) {
|
|
if (empty($activepath)) {
|
|
- $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
|
|
|
+ $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
|
|
|
$fileinfo->filepath = $url . '/' . $savename;
|
|
$fileinfo->filepath = $url . '/' . $savename;
|
|
$fileinfo->filename = basename($savename);
|
|
$fileinfo->filename = basename($savename);
|
|
@@ -259,74 +259,20 @@ class FileManager extends Base
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 处理上传的图片
|
|
|
|
- */
|
|
|
|
- protected function dealUploadImg(File $file, $water, $thumb, $width, $height, $overwrite)
|
|
|
|
- {
|
|
|
|
- $savename = "";
|
|
|
|
- $thumbname = "";
|
|
|
|
-
|
|
|
|
- if ($water == true || $thumb == true) {
|
|
|
|
- $image = Image::open($file);
|
|
|
|
-
|
|
|
|
- if ($water) {
|
|
|
|
- $type = $this->system->water_type ?: Config::get('filesystem.water.type');
|
|
|
|
-
|
|
|
|
- if ($type == 'water') {
|
|
|
|
- $watemark = $this->system->watermark ?: Config::get('filesystem.water.watermark');
|
|
|
|
- $image->water($watemark);
|
|
|
|
- } else {
|
|
|
|
- $watetext = $this->system->watertext ?: Config::get('filesystem.water.watertext');
|
|
|
|
- $image->text($watetext, Config::get('filesystem.water.waterfont'), 30, '#ffffff30');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $savename = $file->hashName();
|
|
|
|
- $realPath = Config::get('filesystem.disks.public.root') . '/' . $savename;
|
|
|
|
-
|
|
|
|
- if ($thumb == true) {
|
|
|
|
- if ($overwrite == true) {
|
|
|
|
- $image->thumb($width, $height, 1);
|
|
|
|
-
|
|
|
|
- $image->save($realPath);
|
|
|
|
- } else {
|
|
|
|
- $image->save($realPath);
|
|
|
|
-
|
|
|
|
- $image->thumb($width, $height, 1);
|
|
|
|
-
|
|
|
|
- $ext = $file->extension();
|
|
|
|
-
|
|
|
|
- $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $savename)) . $this->t_suffix . '.' . $ext;
|
|
|
|
-
|
|
|
|
- $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $image->save($realPath);
|
|
|
|
- }
|
|
|
|
- unset($image);
|
|
|
|
- } else {
|
|
|
|
- $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return [
|
|
|
|
- 'picname' => str_replace('\\', '/', $savename),
|
|
|
|
- 'thumbname' => $thumbname
|
|
|
|
- ];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 图片上传(iframe 页面)
|
|
* 图片上传(iframe 页面)
|
|
*/
|
|
*/
|
|
- public function uploadimg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
|
|
|
|
|
|
+ public function uploadimg(string $img_id = 'picture', $thumb = false, $width = 400, $height = 300,
|
|
|
|
+ $original = false, $id = 0, $cjid = 0)
|
|
{
|
|
{
|
|
View::assign([
|
|
View::assign([
|
|
- 'img_id' => $img_id,
|
|
|
|
- 'water' => $water,
|
|
|
|
- 'thumb' => $thumb,
|
|
|
|
- 'width' => $width,
|
|
|
|
- 'height' => $height,
|
|
|
|
- 'overwrite' => $overwrite
|
|
|
|
|
|
+ 'img_id' => $img_id,
|
|
|
|
+ 'thumb' => $thumb,
|
|
|
|
+ 'width' => $width,
|
|
|
|
+ 'height' => $height,
|
|
|
|
+ 'original' => $original,
|
|
|
|
+ 'id' => $id,
|
|
|
|
+ 'cjid' => $cjid
|
|
]);
|
|
]);
|
|
|
|
|
|
return View::fetch();
|
|
return View::fetch();
|
|
@@ -336,18 +282,21 @@ class FileManager extends Base
|
|
* 本地图片上传
|
|
* 本地图片上传
|
|
* @file upload_file 上传的文件
|
|
* @file upload_file 上传的文件
|
|
* @param string $img_id 图片ipnut text id 默认值 picture
|
|
* @param string $img_id 图片ipnut text id 默认值 picture
|
|
- * @param boolean $water 是否添加水印
|
|
|
|
* @param boolean $thumb 是否制作缩略图
|
|
* @param boolean $thumb 是否制作缩略图
|
|
* @param int $width 缩略图最大宽
|
|
* @param int $width 缩略图最大宽
|
|
* @param int $height 缩略图最大高
|
|
* @param int $height 缩略图最大高
|
|
- * @param bool $overwrite 生成缩略图后是否保存原图
|
|
|
|
|
|
+ * @param int $id 信息ID
|
|
|
|
+ * @param int $cjid 信息临时ID
|
|
|
|
+ * @param bool $saveoriginal 生成缩略图后是否保存原图 默认保存 saveoriginal
|
|
*/
|
|
*/
|
|
- public function uploadLocalImg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
|
|
|
|
|
|
+ public function uploadLocalImg(string $img_id = 'picture', $thumb = false, $width = 400, $height = 300,
|
|
|
|
+ $original = false, $id = 0, $cjid = 0)
|
|
{
|
|
{
|
|
if ($this->request->isPost()) {
|
|
if ($this->request->isPost()) {
|
|
$file = $this->request->file('upload_file');
|
|
$file = $this->request->file('upload_file');
|
|
|
|
+
|
|
if ($file) {
|
|
if ($file) {
|
|
- try {
|
|
|
|
|
|
+ // try {
|
|
validate(
|
|
validate(
|
|
[
|
|
[
|
|
'file' => [
|
|
'file' => [
|
|
@@ -362,21 +311,55 @@ class FileManager extends Base
|
|
'file.fileExt' => '不支持的文件后缀',
|
|
'file.fileExt' => '不支持的文件后缀',
|
|
]
|
|
]
|
|
)->check(['file' => $file]);
|
|
)->check(['file' => $file]);
|
|
-
|
|
|
|
- $arr = $this->dealUploadImg($file, $water, $thumb, $width, $height, $overwrite);
|
|
|
|
|
|
|
|
- return array_merge(
|
|
|
|
- [
|
|
|
|
- 'code' => 0,
|
|
|
|
- 'img_id' => $img_id,
|
|
|
|
- 'picture_url' => Config::get('filesystem.disks.public.url') . '/'
|
|
|
|
- ],
|
|
|
|
- $arr
|
|
|
|
- );
|
|
|
|
|
|
+ $savename = str_replace('\\', '/', $file->hashName()) ;
|
|
|
|
|
|
- } catch (ValidateException $e) {
|
|
|
|
- $this->error($e->getMessage());
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if ($thumb == true) {
|
|
|
|
+ $image = Image::open($file);
|
|
|
|
+
|
|
|
|
+ $image->thumb($width, $height, 1);
|
|
|
|
+
|
|
|
|
+ $ext = $file->extension();
|
|
|
|
+
|
|
|
|
+ $thumbname = str_replace('.' . $ext, '', $savename) . $this->t_suffix . '.' . $ext;
|
|
|
|
+
|
|
|
|
+ if ($original == true) {
|
|
|
|
+ \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
|
+ } else {
|
|
|
|
+ $thumbname = str_replace('.' . $ext, '', $thumbname) . $this->t_suffix . '.' . $ext;
|
|
|
|
+ $savename = $thumbname;
|
|
|
|
+ }
|
|
|
|
+ $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
|
+ } else {
|
|
|
|
+ \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ halt($savename);
|
|
|
|
+
|
|
|
|
+ $fileinfo = new FileManagerModel();
|
|
|
|
+
|
|
|
|
+ $fileinfo->title = $file->getOriginalName();
|
|
|
|
+ $fileinfo->filesize = $file->getSize();
|
|
|
|
+ $fileinfo->filetime = $file->getCTime();
|
|
|
|
+ $fileinfo->fileextension = $file->extension();
|
|
|
|
+ $fileinfo->hash_md5 = $file->md5();
|
|
|
|
+ $fileinfo->filepath = Config::get('filesystem.disks.public.url') . '/' . $savename;
|
|
|
|
+ $fileinfo->filename = basename($savename);
|
|
|
|
+ $fileinfo->username = $this->getSysUser()->username;
|
|
|
|
+ $fileinfo->infoid = $id;
|
|
|
|
+ $fileinfo->cjid = $cjid;
|
|
|
|
+
|
|
|
|
+ $fileinfo->save();
|
|
|
|
+ // $res = FileManagerModel::dealUploadImg($file, $savename, $water, $thumb, $width, $height, $overwrite, $id, $cjid);
|
|
|
|
+
|
|
|
|
+ // return json(array_merge(['code' => 0, 'img_id' => $img_id,], $res));
|
|
|
|
+ // } catch (ValidateException $e) {
|
|
|
|
+ // $this->error($e->getMessage());
|
|
|
|
+ // } catch (Exception $e) {
|
|
|
|
+ // $this->error($e->getMessage());
|
|
|
|
+ // }
|
|
} else {
|
|
} else {
|
|
$this->error('图片不能为空');
|
|
$this->error('图片不能为空');
|
|
}
|
|
}
|
|
@@ -404,7 +387,7 @@ class FileManager extends Base
|
|
|
|
|
|
$file = $fileService->downloadUrlImg($urlImg);
|
|
$file = $fileService->downloadUrlImg($urlImg);
|
|
|
|
|
|
- $arr = $this->dealUploadImg($file, $water, $thumb, $width, $height, $overwrite);
|
|
|
|
|
|
+ $arr = $this->dealUploadImg($file, $thumb, $width, $height, $overwrite);
|
|
|
|
|
|
@unlink($file->realPath);
|
|
@unlink($file->realPath);
|
|
|
|
|
|
@@ -581,4 +564,42 @@ class FileManager extends Base
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理上传的图片
|
|
|
|
+ */
|
|
|
|
+ protected function dealUploadImg(File $file, $thumb, $width, $height, $overwrite, $id = 0, $cjid = 0)
|
|
|
|
+ {
|
|
|
|
+ $savename = $file->hashName();
|
|
|
|
+
|
|
|
|
+ if ($thumb == true) {
|
|
|
|
+ $image = Image::open($file);
|
|
|
|
+
|
|
|
|
+ if ($overwrite == true) {
|
|
|
|
+ $image->thumb($width, $height, 1);
|
|
|
|
+
|
|
|
|
+ $realPath = Config::get('filesystem.disks.public.root') . '/' . $savename;
|
|
|
|
+
|
|
|
|
+ $image->save($realPath);
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ $ext = $file->extension();
|
|
|
|
+
|
|
|
|
+ $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $savename)) . $this->t_suffix . '.' . $ext;
|
|
|
|
+
|
|
|
|
+ $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ unset($image);
|
|
|
|
+ } else {
|
|
|
|
+ $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $picture_url = Config::get('filesystem.disks.public.url') . '/';
|
|
|
|
+
|
|
|
|
+ return [
|
|
|
|
+ 'picname' => $picture_url . str_replace('\\', '/', $savename),
|
|
|
|
+ 'thumbname' => $thumbname ? $picture_url . $thumbname : ""
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
}
|
|
}
|