first commit

This commit is contained in:
2020-08-06 16:37:53 +08:00
commit 91311c63a4
12865 changed files with 1504178 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use File;
use Illuminate\Http\Request;
use Storage;
class StorageController extends Controller
{
public function index(Request $request)
{
$File = $request->file('image');
$oldName = $File->getClientOriginalName();
$hash = File::hash($File->path());
$size = File::size($File->path());
if ($size > (10 * 1024 * 1024)) {
return [
'code' => 0,
'message' => '文件不能超过10M',
];
}
$pathUrl = 'images' . date('/Y-m/d');
$fileName = $hash . '.' . $File->getClientOriginalExtension();
$path = Storage::disk('public')->putFileAs(
$pathUrl, $File, $fileName
);
if (!$path) {
return [
'code' => 0,
'message' => '文件上传失败',
];
}
return [
'code' => 1,
'message' => '文件上传成功',
'path' => '/' . $pathUrl . '/' . $fileName,
];
}
}