0

I was try to upload using Laravel. here's my Add Images Modal:

<div id="imagesModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"></h4>
            </div>
            <div class="modal-body">
            <form name="imagesForm" id="addImages" class="form-horizontal dropzone" role="form" method="POST" action="{{ route('images.add') }}" enctype="multipart/form-data">
                {{ csrf_field() }}
            </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

here's my jquery and dropzone settings:

$( "#addImages" ).click(function(event) {
                event.preventDefault();
                save_method = 'add';
                $('#imagesModal').modal("show");
                $('.modal-title').text('Add Images')
            });

            Dropzone.options.addImages = {
                paramName: "images", // The name that will be used to transfer the file
                maxFilesize: 2, // MB

                /*params: {
                    'id' : $('#addImages').attr('data-gallery-id')
                }*/
            };

and in controller for images.add i have a function like this:

public function store(Request $request)
    {
        foreach ($request->file as $file) {
            $image = new Image();
            $image->gallery_id = 7;
            $image->name = $file->getClientOriginalName();
            $image->extension = $file->extension();
            $image->size = $file->getClientSize();
            $image->save();

            // Or any custom name as the third argument
            Storage::putFileAs('public'.'/'.'test'. '/', $file, $file->getClientOriginalName());

            return response($file->getClientOriginalName(). 'uploaded succesfully');
        }
    }

it was uploaded without any errors in my console, and in response it give 200. but the problem is no images is uploaded and no data was saved. so how can i check which part of my code that has an errors? or how can i fix this?

Ying
  • 1,282
  • 4
  • 19
  • 34
  • have you initalized the dropzone class ? eg: var myDropzone = new Dropzone("div#myId", { url: "/file/post"}); – KPK Dec 08 '17 at 08:02
  • no not yet. above is all my code. but why i should initialize it? isn't giving the form with .dropzone is not enough? – Ying Dec 08 '17 at 08:20
  • do one thing dd(Input::all); before fore in controller and check what it's shows. there you can find weather there is image or not also use input ; – Gaurav Gupta Dec 08 '17 at 08:31
  • 1
    You are using a return statement in your foreach loop, so if multiple images are sent to the server, only the first one will be saved. – Jerodev Dec 08 '17 at 08:32
  • @Ying : If you'd want to pass multiple files to the serve, pass `uploadMultiple` option to dropzone as `true` – linktoahref Dec 08 '17 at 09:19
  • @linktoahref i put that params but i still got nothing. – Ying Dec 08 '17 at 09:35
  • Could you update your question with the response of `dd($request->all())` from your store method? – linktoahref Dec 08 '17 at 10:07
  • @linktoahref since it's using Ajax i got no result. – Ying Dec 08 '17 at 10:34
  • check it on browser network – Gaurav Gupta Dec 08 '17 at 11:10
  • ok i use the response($request->all()) and it give me this 0 {…} _token LOxhUr3Jm4WaBJtT1jJWEHCGo78C9IHs9aMZJ5OT file {}. it seem there is no data was send. not sure what wrong with my configuration or maybe the modal which cause it. – Ying Dec 08 '17 at 11:24
  • you can check what you send from browser to you controller just check it in your networks , weather it's sending problem – Gaurav Gupta Dec 08 '17 at 11:54

0 Answers0