Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

delete image form s3 bucket in laarvel 8

<?php
namespace AppHttpControllers;

use IlluminateHttpRequest;
use IlluminateSupportFacadesStorage;

class UploadController extends Controller
{

    public function index()
    {
        $files = Storage::disk('s3')->files('files');

        $data = [];
        foreach($files as $file) {
            $data[] = [
                'name' => basename($file),
                'downloadUrl' => url('/download/'.base64_encode($file)),
                'removeUrl' => url('/remove/'.base64_encode($file)),
            ];
        }

        return view('upload', ['files' => $data]);
    }

    public function store(Request $request)
    {
        $this->validate($request, [
            'file' => 'required|max:2048'
        ]);

        if ($request->hasFile('file')) {
            $file = $request->file('file');
            $name = time() . $file->getClientOriginalName();
            $filePath = 'files/' . $name;
            Storage::disk('s3')->put($filePath, file_get_contents($file));
        }

        return back()->withSuccess('File uploaded successfully');
    }

    public function destroy($file)
    {
        $file = base64_decode($file);
        Storage::disk('s3')->delete($file);
        return back()->withSuccess('File was deleted successfully');
    }

    public function download($file) 
    {
        $file = base64_decode($file);
        $name = basename($file);
        Storage::disk('s3')->download($file, $name);
        return back()->withSuccess('File downloaded successfully');
    }
}
Source by arjunphp.com #
 
PREVIOUS NEXT
Tagged: #delete #image #form #bucket #laarvel
ADD COMMENT
Topic
Name
5+9 =