rashan88's avatar

MethodNotAllowedHttpException come when i am trying to upload 15Mb file

MethodNotAllowedHttpException is come when i am trying to upload 15 Mb file. i changed post_max_size and other configuration on the php.ini file

0 likes
8 replies
nsvetozarevic's avatar

MethodNotAllowedHttpException shouldn't be thrown because of the post_max_size. Are you sure your form has right type of HTTP request ?

Snapey's avatar

A request that is too large can cause the payload to be truncated and @csrf or @method fields to be lost

You need to change both post_max_size and upload_max_filesize

I would then create a route that calls phpinfo() and check that the settings are in place (don't check it from the command line)

1 like
rashan88's avatar

@nikos i am this is my js code

``$("#add-property-button").click(function (e) { e.preventDefault();

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('#_token').val()
        }
    });
            console.log( $('input[type=file]')[0].files);

    var formdata = new FormData();

    var files =$('input[type=file]')[0].files;
    
    for(var i=0;i<files.length;i++){
        formdata.append("images[]", files[i], files[i]['name']);
    }
    formdata.append("property_type",$('#property_type').val());
    formdata.append("purpose-type",$('#purpose-type').val());
    formdata.append("location",$("#txtlocation").val());
    formdata.append("rooms",$("#txtrooms").val());
    formdata.append("landsize",$("#txtlandsize").val());
    formdata.append("bathsize",$("#txtbathsize").val());
    formdata.append("housesize",$("#txthousesize").val());
    formdata.append("address",$("#txtaddress").val());
    formdata.append("description",$("#txtdescription").val());
    formdata.append("cost",$("#txtcost").val());
    formdata.append("is_negotiable",$("#is_negotiable").val());
    formdata.append("name",$("#txtname").val());
    formdata.append("phone",$("#txtphone").val());
    formdata.append("email",$("#txtemail").val());
    formdata.append("_token",$('#_token').val());

    jQuery.ajax({
        url: 'upload-property',
        method: 'POST',
        data: formdata,
        contentType: false,
        processData: false,
        beforeSend: function (xhr) {

        },
        success: function (respond) {
         if(respond.success){
             window.location.href ='http://localhost/test/public/user-profile';
         }
         if(!respond.success){
             $('#message').html("<div class='alert alert-danger text-center'>"+respond.message+"</div>");

         }

        },
        complete: function (jqXHR, textStatus) {

        }
    });

});``
nsvetozarevic's avatar

Are you sure that url: 'upload-property', get the right url, I personally don't like putting urls like this in .js . You can put your whole url in some hidden field, and then read it from js. Or there are libraries like https://github.com/tightenco/ziggy which let you export your routes, and use your access them by name inside js code

Snapey's avatar

Did you check your settings or what?

THe current questioning could be eliminated by just saying if smaller uploads work

Please or to participate in this conversation.