Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel 9 Multiple File Upload Tutorial

<?php

  

namespace AppHttpControllers;

  

use IlluminateHttpRequest;

use AppModelsFile;

  

class FileController extends Controller

{

    /**

     * Display a listing of the resource.

     *

     * @return IlluminateHttpResponse

     */

    public function index()

    {

        return view('fileUpload');

    }

    

    /**

     * Display a listing of the resource.

     *

     * @return IlluminateHttpResponse

     */

    public function store(Request $request)

    {

        $request->validate([

            'files' => 'required',

            'files.*' => 'required|mimes:pdf,xlx,csv|max:2048',

        ]);

      

        $files = [];

        if ($request->file('files')){

            foreach($request->file('files') as $key => $file)

            {

                $fileName = time().rand(1,99).'.'.$file->extension();  

                $file->move(public_path('uploads'), $fileName);

                $files[]['name'] = $fileName;

            }

        }

  

        foreach ($files as $key => $file) {

            File::create($file);

        }

     

        return back()

                ->with('success','You have successfully upload file.');

   

    }

}
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #Laravel #Multiple #File #Upload #Tutorial
ADD COMMENT
Topic
Name
2+3 =