Tuesday, May 1, 2018

Multiple Files Uploading in Laravel - development

Multiple Files Uploading in Laravel

I have been trying to upload multiple files in Laravel. There are few solutions to this problem in Stackoverflow, but none works for me.

This is my store method:

public function bulkstore(Request $request)
    {
        foreach ($request->file_name as $file) {

            if ($request->hasFile('file')) {
                $fileNameWithExt = $request->file('file')->getClientOriginalName();
                $fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
                $extenstion = $request->file('file')->getClientOriginalExtension();
                $fileNameToStore = $fileName.'.'.$extenstion;
                $path = $request->file('file')->storeAs('public/images', $fileNameToStore);
            }

            File::create([
                'file_name' => $fileNameToStore,
            ]);
        }

        return redirect('/file');
    }

I am getting this error:

Undefined variable: fileNameToStore

This method works for single file, but not for multiple file. Any suggestion?



from Laravel Questions and Answers https://laravelquestions.com/php/multiple-files-uploading-in-laravel/
via Lzo Media

No comments:

Post a Comment