bakalarska_praca/app/Http/Controllers/UploadController.php
2023-05-11 21:57:12 +02:00

29 lines
698 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
class UploadController extends Controller
{
public function store(Request $request)
{
// Get the uploaded file
$file = $request->file('file');
// Generate a unique file name
$file_name = date('YmdHis') . '.' . $file->getClientOriginalExtension();
// Save the file to the public/uploads directory
$path = $file->storeAs('uploads', $file_name, 'public');
// Return a JSON response with the file name and upload status
return response()->json([
'filename' => $file_name,
'status' => 'success'
]);
}
}