Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax not post base64 data of large image

I am passing Image base64 data through ajax to my php function, but for large size image Ajax does not post the data. But the same code works perfectly for small images.

srcdata=data:image/jpeg;base64,/9j/4SxvRXhpZgAASUkqAAgAAAANAAABBAABAAAAwAwAAAEBBAABAAAALAcAAA8BAgAIAAAAqgAAABABAgARAAAAsgAAABIBAwABAAAABgAAABoBBQABAAAAxAAAABsBBQABAAAAzAAAACgBAwABAAAAAgAAADEBAgAMAAAA1AAAADIBAgAUAAAA4AAAABMCAwABAAAAAQAAAGmHBAABAAAA9AAAACWIBAABAAAA3gkAAPAJAABTQU1TVU5HAFNBTVNVTkctU0dILUk1MzcAAEgAAAABAAAASAAAAAEAAABJNTM3VUNVQ05DOQAyMDE0OjA2OjIyIDEwOjE3OjEwACEAmoIFAAEAAACGAgAAnYIFAAEAAACOAgAAIogDAAEAAAADAAAAJ4gDAAEAAAB9AAAAAJAHAAQAAAAwMjIwA5ACABQAAACWAgAABJACABQAAACqAgAAAZEHAAQAAAABAgMAAZIKAAEAAAC AgAAApIFAAEAAADGAgAAA5IKAAEAAADOAgAABJIKAAEAAADWAgAABZIFAAEAAADeAgAAB5IDAAEAAAACAAAACJIDAAEAAAAAAAAACZIDAAEAAAAAAAAACpIFAAEAAADmAgAAfJIHAGIAAABeCQAAhpIHAFwGAADuAgAAAKAHAAQAAAAwMTAwAaADAAEAAAABAAAAAqAEAAEAAADADAAAA6AEAAEAAAAsBwAABaAEAAEAAADACQAAF6IDAAEAAAACAAAAAaMDAAEAAAABAAAAAqQDAAEAAAAAAAAAA6QDAAEAAAAAAAAABKQFAAEAAABKCQAABqQDAAEAAAAAAAAACaQDAAEAAAAAAAAACqQDAAEAAAAAAAAAIKQCAAsAAABSCQAAAAAAAAEAAAAUAAAABAEAAGQAAAAyMDE0OjA2OjIyIDEwOjE3OjEwADIwMTQ6MDY6MjIgMTA6MTc6MTAAAQAAABQAAAAUAQAAZAAAAFAAAAABAAAAAAAAA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AAAPAAAAFMwOFFFTENHQzAxAAcAAQAHAAQAAAAwMTAwAgAEAAEAAAAAIAEADAAEAAEAAAAAAAAAEAAFAAEAAABaAAAAQAAEAAEAAAAAAAAAUAAEAAEAAAABAAAAAAEDAAEAAAAAAAAAAAAAAAAAAAAAAAAAAgABAAIABAAAAFI5OAACAAcABAAAADAxMDAAAAAAAQAAAAEABAAAAAICAAAAAAAACQAAAQQAAQAAAAABAAABAQQAAQAAAJAAAAADAQMAAQAAAAYAAAASAQMAAQAAAAYAAAAaAQUAAQA `

data is too large so partially posted ,

ajax

count = 1;
name='test'
jQuery.ajax({
    url:"/createImage.php",
    data:{img_data:srcdata,img_id:count,name:name},
    type:"POST",
    contentType:"application/x-www-form-urlencoded",
    success:function(result)
    {
        alert(result);
    }
});

PHP

print_r($_POST); // is empty when logging..

When I'm trying to get the post data in php I am getting empty . What could be the reason for ajax not sending the data when base64 is used.

like image 469
Manikandan Arunachalam Avatar asked Feb 03 '15 10:02

Manikandan Arunachalam


1 Answers

I agree with TrueBlueAussie. This looks like a server side setting in PHP.

Open you php.ini file and find the line stating upload_max_filesize. The default it set to 2M, which is 2MB. Try increasing it to 3MB and see if you are still receiving the error.

Note: You'll need to restart Apache/Nginx/webserver for this to take affect from the php.ini file.

Even though you are sending the file as a variable, the application/x-www-form-urlencoded might be interpreted in PHP as being an actual file upload. The other php.ini setting you can take a look at will be post_max_size which has a default of 8M, which is the maximum that you can POST to your PHP script.

like image 76
Donovan Solms Avatar answered Oct 09 '22 23:10

Donovan Solms