Search
 
SCRIPT & CODE EXAMPLE
 

PHP

delete image s3 laravel

Storage::disk('s3')->delete('path/to/image/in/bucket'); 
Comment

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');
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: Class "AppUser" not found 
Php :: symfony password 
Php :: php json encode 
Php :: laravel 8 created at format 
Php :: php array longest string 
Php :: how to convert array to string with commas in php 
Php :: get template part wordpress 
Php :: convert xml file to array php 
Php :: str_replace php 
Php :: how to get only decimal value in php 
Php :: table has column laravel 
Php :: php number_format 
Php :: php mail function from name 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) 
Php :: wp logs 
Php :: laravel create search 
Php :: php qrscanner webcam 
Php :: eloquent delete all where 
Php :: php copy 
Php :: php remove array element reset keys 
Php :: associative array sorting by value in php 
Php :: livewire sortable 
Php :: add hour minute in datetime in php 
Php :: select max id laravel 
Php :: send value from one page to another in php 
Php :: php stop execution 
Php :: how to start laravel project 
Php :: IlluminateDatabaseEloquentCollection to array 
Php :: snap store phpstrom 
Php :: difference entre deux date php 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =