samedi 2 janvier 2021

file upload validation in Laravel

I use a javascript code to upload multiple files on the server. the problem is that when I upload multiple files with 10 MByte size and the server storage only has space for 5 Mbyte then some of the files will upload and some not. I want to send the response name of uploaded files and not uploaded files. I use the code below and it only throws an exception StorageLimit. This is function in Model Class Post:

  public function newcmspost(Request $request){
        $names = [];
        $paths ="succes";
        $erpaths = "error";
        $index = 0;
        foreach ($request->file('files') as $file){
            $names[$index] = $file->getFilename();
            try{
                $paths = $paths."/ ". $file->store('public/images');

            }catch (Exception $e){
                $erpaths = $paths."/".$file->getFilename();
            }
        }
        return response("long responce".$paths);
    }

1 - I want a response like:

error : filename1\ .... success : filenamesucess1 \ ...

2 - and also I want to prevent default throw error on StorageLimit. thank you all.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire