@rollin
To upload an image to a server using PHP Laravel, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
use IlluminateSupportFacadesStorage;
public function uploadImage(Request $request)
{
$image = $request->file('image');
if ($image) {
$path = $image->store('images', 'public');
// You can also save the path to the image in your database if needed
}
return redirect()->back()->with('success', 'Image uploaded successfully.');
}
|
1
|
Route::post('/upload', 'ImageController@uploadImage');
|
1 2 3 4 5 |
<form action="{{ url('/upload') }}" method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="image">
<button type="submit">Upload Image</button>
</form>
|
By following these steps, you should be able to successfully upload an image to your server using PHP Laravel.