Laravel File Storage

Laravel File Storage

Instructor-svgAl-Mamun Sarkar
Jul 20 , 2020
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram

এই লেসনে লারাভেল এর File Storage নিয়ে আলোচনা করবো।দেখবো কিভাবে Laravel এ File upload or Image upload, File Delete করতে হয়। 

 

Source Code:

Routes:

Route::view('file-upload', 'upload.image');

Route::post('file-upload', 'ImageUploadController@store');
Route::get('files', 'ImageUploadController@files');
Route::get('delete-file', 'ImageUploadController@delete');

 

ImageUploadController:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use File;

class ImageUploadController extends Controller
{
    public function store(Request $request)	
    {
    	// echo $request->file('image')->getClientOriginalName();
    	// echo $request->file('image')->extension();
    	$path = $request->file('image')->store('images');

    	return $path;
    }


    public function files()
    {
    	echo $url = Storage::url('images/I9dbPk2SwQUJrVik3UVNfITPe7wp3JWxehY6d7XT.jpeg');
    	echo " <img src='$url'>";
    }

    public function delete()
    {
    	Storage::disk('public')->delete('images/I9dbPk2SwQUJrVik3UVNfITPe7wp3JWxehY6d7XT.jpeg');
    }
}

 

file_upload.blade.php

<form action="file-upload" method="post" enctype="multipart/form-data">
    @csrf
    <div>
        <input type="file" name="image" id="image">
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>