samedi 2 janvier 2021

file upload validation in Laravel

I use a javascript code to upload multiple files to the server. the problem is that when I upload multiple files with 10 MByte size for example 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 the function in Model Class Post that I use to handle upload files:

  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.



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

Aucun commentaire:

Enregistrer un commentaire