1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| $name = 'upload'; if ($request->hasFile($name)){ $file = $request->file($name); $time = date('Ymd',time()); if ($file->isValid()) { $originalName = $file->getClientOriginalName(); $ext = $file->getClientOriginalExtension(); $realPath = $file->getRealPath(); $type = $file->getClientMimeType(); $filename = uniqid() . '.' . $ext; $path = 'editor/'.$time.'/'.$filename; $bool = Storage::disk('admin')->put('/'.$path, file_get_contents($realPath)); if (!$bool) return response()->json([ 'uploaded' => 0, 'error' => '上传失败', ]); return response()->json([ 'uploaded' => 1, "fileName" => $filename, "url" => '/upload/'.$path ]); } } return response()->json([ 'uploaded' => 0, 'error' => '上传失败', ]);
|