mardi 9 février 2021

Get Directory and upload files form one directory to another without any interface Laravel 8

Here I get the directory "filesToUpload" where I saved the two images and I am trying to upload these images from the directory to another directory "destination" in the storage and want to store the title of the image, extension and size.**

<?php
    
    namespace App\Http\Controllers;
    
    use App\Models\Images;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Storage;
    use File;
    
    class ImagesController extends Controller
    
    {
        public function getFiles(Request $request){
        
            $request->validate([
    
                'file' => 'required|file|mimes:jpg,jpeg,bmp,png',
            ]);
    
        $path = public_path('/filesToUpload');
        $files = File::files($path);
        if($files){
            // dd($files);
    
            foreach ($files as $file){
                $file = time().'.'.$request->file->extension();  
         
                $request->file->store(public_path('/destination'), $file);
    
                $title = File::create(['title' => $file->getClientOriginalName()]);
                $ext = File::create(['extension' => $file->getClientOriginalExtension()]);
                $size = File::create(['size' => $file->getSize()]);
    
                $save = new foto;
                $save->title = $title;
                $save->ext = $ext;
                $save->size = $ext;
    
                return back()
                ->with('success','You have successfully file uplaod.')
                ->with('file',$file);  
            }
        }
        else
            {
                return back()
                ->with('danger','You have No file in the directory to upload.');
            }
        }
    }

**



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3tBRuuh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire