|
@@ -3,7 +3,7 @@
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
-use Tinywan\Storage\Storage;
|
|
|
+use support\Storage;
|
|
|
|
|
|
class UploadFile
|
|
|
{
|
|
@@ -14,18 +14,58 @@ class UploadFile
|
|
|
*
|
|
|
* @return \support\Response
|
|
|
*/
|
|
|
- public function upload()
|
|
|
+ public function upload($config)
|
|
|
{
|
|
|
- $config = config('plugin.tinywan.storage.app.storage.local');
|
|
|
- $config['single_limit'] = 123;
|
|
|
- $res = Storage::uploadFile($config);
|
|
|
- $data = [
|
|
|
- 'url' => $res[0]['url'],
|
|
|
- 'path' => 'storage/'.date('Ymd').'/'.$res[0]['save_name'],
|
|
|
- 'size' => $res[0]['size'],
|
|
|
- 'mime_type' => $res[0]['mime_type'],
|
|
|
- ];
|
|
|
+ try {
|
|
|
+ $res = Storage::uploadFile($config);
|
|
|
+ $data = [
|
|
|
+ 'url' => $res[0]['url'],
|
|
|
+ 'path' => $config['path'] . date('Ymd') . '/' . $res[0]['save_name'],
|
|
|
+ 'size' => $res[0]['size'],
|
|
|
+ 'mime_type' => $res[0]['mime_type'],
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_fail('上传失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
|
|
|
return json_success('上传成功', $data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 上传图片
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/2/26 17:16
|
|
|
+ *
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public function image()
|
|
|
+ {
|
|
|
+ $config = [
|
|
|
+ 'single_limit' => 1024 * 5,
|
|
|
+ 'nums' => 1,
|
|
|
+ 'include' => ['jpg', 'jpeg', 'png'],
|
|
|
+ 'filePath' => 'storage/images/'
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $this->upload($config);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 上传视频
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/2/26 17:16
|
|
|
+ *
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public function video()
|
|
|
+ {
|
|
|
+ $config = [
|
|
|
+ 'single_limit' => 1024 * 1024 * 50,
|
|
|
+ 'nums' => 1,
|
|
|
+ 'include' => ['mp4'],
|
|
|
+ 'filePath' => 'storage/videos/'
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $this->upload($config);
|
|
|
+ }
|
|
|
}
|