|
@@ -627,19 +627,12 @@ class User extends BaseController
|
|
|
}
|
|
|
$base64 = 'data:'.$reponse['contentType'].';base64,'.base64_encode($data['buffer']);
|
|
|
|
|
|
-
|
|
|
+ $this->uploadImageBase64("wximg",$base64);
|
|
|
|
|
|
return app('json')->success(["data"=>$data,"res"=>\think\facade\Filesystem::disk('resource')]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- *
|
|
|
- * @param type $code
|
|
|
- * @param type $base64
|
|
|
- */
|
|
|
- public function uploadImageBase64($code,$base64){
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -649,7 +642,7 @@ class User extends BaseController
|
|
|
* @return type
|
|
|
*/
|
|
|
public function upload(Request $request){
|
|
|
- $uploadConfig = config('upload');
|
|
|
+ $uploadConfig = config('filesystem');
|
|
|
$sysData = (new SysModel())->where("id",1)->find();
|
|
|
$file = $request->file('file');
|
|
|
$code = $request->post("code","image");
|
|
@@ -683,7 +676,7 @@ class User extends BaseController
|
|
|
* @return type
|
|
|
*/
|
|
|
public function uploadVideo(Request $request){
|
|
|
- $uploadConfig = config('upload');
|
|
|
+ $uploadConfig = config('filesystem');
|
|
|
$sysData = (new SysModel())->where("id",1)->find();
|
|
|
$file = $request->file('file');
|
|
|
$code = $request->post("code","video");
|
|
@@ -706,6 +699,76 @@ class User extends BaseController
|
|
|
return app('json')->success(['video'=>$imgUrl]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * base64文件上传
|
|
|
+ * @param type $code
|
|
|
+ * @param type $base64
|
|
|
+ */
|
|
|
+ public function uploadImageBase64($code,$base64){
|
|
|
+ $sysData = (new SysModel())->where("id",1)->find();
|
|
|
+ $uploadConfig = config('filesystem');
|
|
|
+
|
|
|
+ preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
|
|
|
+ if(!$result){
|
|
|
+ return ["code"=>-1,"msg"=>"base64格式格式错误"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
|
|
|
+ return ["code"=>-1,"msg"=>"不支持的图片格式"];
|
|
|
+ }
|
|
|
+ $rootPath = config('filesystem.disks.resource.root');
|
|
|
+ $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
|
|
|
+ $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
|
|
|
+ $path = dirname($filePath);
|
|
|
+
|
|
|
+ if (!is_dir($path)) {
|
|
|
+ return ["code"=>-1,"msg"=>"上传目录不存在"];
|
|
|
+ }
|
|
|
+ if (!mkdir($path, 0777, true)) {
|
|
|
+ return ["code"=>-1,"msg"=>"生成目录失败"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_file($filePath)) {
|
|
|
+ return ["code"=>-1,"msg"=>"文件已存在"];
|
|
|
+ }
|
|
|
+ if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
|
|
|
+ return ["code"=>-1,"msg"=>"文件报错失败"];
|
|
|
+ }
|
|
|
+ $savePath = $sysData['system_url'].config('filesystem.disks.resource.url').DIRECTORY_SEPARATOR.$hashName;
|
|
|
+ return ["code"=>1,"url"=>str_replace("\\", "/", $savePath)];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|