小编典典

Ajax不会发布大图的base64数据

ajax

我正在通过ajax将Image base64数据传递给我的php函数,但是对于大尺寸图像,Ajax不会发布数据。但是,相同的代码对于小图像非常适用。

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

数据太大,因此部分发布了,

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..

当我尝试获取php中的发布数据时,我越来越空了。使用base64时,ajax不发送数据的原因可能是什么?


阅读 272

收藏
2020-07-26

共1个答案

小编典典

我同意TrueBlueAussie的观点。这看起来像PHP中的服务器端设置。

打开php.ini文件,然后找到行upload_max_filesize。默认设置为2M,即2MB。尝试将其增加到3MB,然后查看是否仍然收到错误。

注意:您需要重新启动Apache / Nginx / webserver才能从php.ini文件中生效。

即使您将文件作为变量发送,application/x-www-form- urlencoded也可能在PHP中将其解释为实际的文件上传。php.ini您可以查看的另一个设置post_max_size是默认设置8M,这是您可以发布到PHP脚本的最大值。

2020-07-26