master_template/app/Http/Controllers/FileController.php

21 lines
516 B
PHP
Raw Permalink Normal View History

2024-06-10 12:21:58 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
{
public function upload(Request $request)
{
$file = $request->file('upload');
$filename = uniqid() . '_' . $file->getClientOriginalName();
Storage::disk('public')->put($filename, file_get_contents($file));
$url = asset('storage/' . $filename);
return response()->json([
'url' => $url,
]);
}
}