0

I'm using dynamic input generate function through that I try to upload multiple images upload I got code from the internet and I modified according to my requirement images uploading is working when I the name into the table that time only I'm getting issues.

I can't understand how to do that. Please help how to do that.

I attached my codes, UI, table screenshot.

Inserting Code

$Colorimages=array();


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

                foreach($files as $file)
                {
                    $extension = $file->getClientOriginalExtension();
                    $filename = date('YmdHis').rand(1,9999).'.'.$extension;
                    $file->move(public_path("product_images/sub_images"), $filename);
                    $Colorimages[]=$filename;
                }

            }

if(count($request->prol_product_line_code)>0)
        {
            foreach ($request->prol_product_line_code as $prol=>$v)
            {
                $data2=array
                (
                    'prol_product_code' => $request->prod_product_code,
                    'prol_product_line_code' => $request->prol_product_line_code[$prol],
                    'prol_printed' => $request->prod_printed,
                    'prol_color' => $request->prol_color[$prol],
                    'prol_image1' => $Colorimages[$prol],
                    'prol_image2' => $Colorimages[$prol],
                    'prol_image3' => $Colorimages[$prol],
                );
                product_line::insert($data2);
            }
        }

enter image description here

enter image description here

1 Answer 1

1

This is the way to upload multiple images in laravel.

Step 1: Create Routes(routes/web.php)

Route::get('image-view','ImageController@index');
Route::post('image-view','ImageController@store');

Step 2: Create ImageController File(app/Http/Controllers/appController.php)

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;


class ImageController extends Controller
{
    public function index()
    {
        return view('image-view');
    }
    public function store(Request $request)
    {
        $imageName = request()->file->getClientOriginalName();
        request()->file->move(public_path('upload'), $imageName);
        return response()->json(['uploaded' => '/upload/'.$imageName]);
    }
}

Step 3: Create Blade File(resources/views/index.blade.php)

 <div class="container">
        <div class="row">
            <div class="col-lg-8 col-sm-12 col-11 main-section">
                <h1 class="text-center text-danger">File Input Example</h1><br>

                    {!! csrf_field() !!}
                    <div class="form-group">
                        <div class="file-loading">
                            <input id="file-1" type="file" name="file" multiple class="file" data-overwrite-initial="false" data-min-file-count="2">
                        </div>
                    </div>

            </div>
        </div>
    </div>
<script type="text/javascript">
        $("#file-1").fileinput({
            theme: 'fa',
            uploadUrl: "/image-view",
            uploadExtraData: function() {
                return {
                    _token: $("input[name='_token']").val(),
                };
            },
            allowedFileExtensions: ['jpg', 'png', 'gif'],
            overwriteInitial: false,
            maxFileSize:2000,
            maxFilesNum: 10,
            slugCallback: function (filename) {
                return filename.replace('(', '_').replace(']', '_');
            }
        });
    </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.