Shivdhwaj Pandey
Shivdhwaj Pandey

Reputation: 157

Heavy Images Not Uploading Ajax/Jquery, FormData is empty

I am running this code which is working fine for small size of images upto 2.5mb each image and the form have to take maximum of 8 imgaes but when I used to get the images more than 4mb more that 1 in the form it sends blank

$_POST

and

$_FILES

while if i select only one file of 6mb its uploading fine, But when I upload the multiple files then it sends me blank data at server side.

The form contains 8 input fields of file type [Not multiple ones]

$('#'+Id+'_form').submit(function(e){
        var formObj = $(this);
        var formURL = formObj.attr("action");
        var formData = new FormData(this);
        $.ajax({
            url: formURL,
            type: 'POST',
            data:  formData,
            mimeType:"multipart/form-data",
            contentType: false,
            cache: false,
            processData:false,
            success: function(data, textStatus, jqXHR)
            {
                if(data){
                    data = jQuery.parseJSON( data );
                    for (var key in data) {
                        if (data.hasOwnProperty(key)) {
                            var html = '<span>Uploaded</span>';
                           // $('#'+data[key].upload+'_id').hide();
                            $('#'+data[key].upload+'_id').after(html);
                        }
                     }
                    $('#'+Id+'_uploadButton').val('Uploaded Successfully');
                }else{
                    $('#'+Id+'_uploadButton').val('Error Occurred !!!');
                }
            },
            error: function(jqXHR, textStatus, errorThrown) 
            {
            }          
        });
        e.preventDefault(); //Prevent Default action. 
        /*e.unbind();*/
    }); 
    $('#'+Id+'_form').submit();

Upvotes: 0

Views: 842

Answers (2)

Xmindz
Xmindz

Reputation: 1282

This may be because of the default request length allowed by your server. Try setting it in the php.ini as follows:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

Upvotes: 1

S.Pols
S.Pols

Reputation: 3434

Try this in your php.ini

  • post_max_size=30M
  • upload_max_filesize=30M

Or try it in your htaccess:

  • php_value post_max_size 30M
  • php_value upload_max_filesize 30M

Upvotes: 1

Related Questions