I'm trying to upload images to the database using Ajax Jquery.It works fine for small files (less than 100kb) and gets uploaded to the database. I have changed the php.ini for file uploading limits(upload_max_filesize = 40M) and post upload limits to 40M(post_max_size = 41M) and tried to upload an image with 300kb but still nothing. When i click on console, i see "No response data".
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 url = '';
    var form = $('form')[0]; 
    var formData = new FormData(form);
    formData.append('_token', token); // adding token
    $.ajax({
        url: url,
        data: formData, 
        type: 'POST',
        contentType: false,
        processData: false, 
        success:function(data){
         console.log(data);
        }
    });
  });
});
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire