samedi 30 novembre 2019

Submitting large files Laravel and Ajax

I have a form where user submit and add product with multiple images to the database through Ajax request. The problem is when I choose a lower(12kb) image it save the product but if it is large file(1mb) or (400kb) it doesn't save the product. I have set the limit of upload to 10000mb, how can I fix this issue?

Controller

  public function store(Request $request)
{

   // ($request->all());
    $formInput=$request->except('filename');

    $product = product::create(array_merge($formInput, [
        'seller_id'=> Auth::user()->id,
        'user_id' => Auth::user()->id
    ]));
    foreach ($request->photos as $photo) {
       $filename = $photo->store('public/photos');
        ProductsPhoto::create([
            'product_id' => $product->id,
            'filename' => $filename
        ]);
    }

}

Ajax

 var token = $("#token").val();
 $(document).ready(function(){
 $("#btn").click(function(){
    var form = $('form')[0]; 
    var formData = new FormData(form);
    formData.append('_token', token); // adding token
    $.ajax({
        url: "<?php echo url('seller/product') ?>",
        data: formData, 
        type: 'POST',
        contentType: false, 
        processData: false,
        success:function(data){
         console.log(data);
        }
    });
  });
});


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire