jQuery base64图像在php中不验证

jQuery base64图像在php中不验证,php,jquery,image,base64,Php,Jquery,Image,Base64,在jQuery端,我通过以下代码获得base64图像 $(input).files[0].convertToBase64(function(base64){ alert(base64); // this code }); File.prototype.convertToBase64 = function(callback){ var reader = new FileReader(); reader.onloadend = function (e) { c

在jQuery端,我通过以下代码获得base64图像

$(input).files[0].convertToBase64(function(base64){
    alert(base64); // this code
});
File.prototype.convertToBase64 = function(callback){
    var reader = new FileReader();
    reader.onloadend = function (e) {
        callback(e.target.result, e.target.error);
    };
    reader.readAsDataURL(this);
};
这是正确的

但当我将图像发送到php服务器时,php不会验证图像,而是验证代码

public static function check_base64_image($base64) {
        if($base64 === '') return true;
        $img = imagecreatefromstring(base64_decode($base64));
        if (!$img) {
            return false;
        }

        imagepng($img, 'tmp.png');
        $info = getimagesize('tmp.png');

        unlink('tmp.png');

        if ($info[0] > 0 && $info[1] > 0 && $info['mime']) {
            return true;
        }

        return false;
}

问题是什么?

您如何发送和接受数据?数据是否被发送到服务器?你能验证你在php端收到了什么数据吗?我用angular$http.post发送数据,服务器端是laravel,我检查接收数据并使用base64到图像转换器站点,工作正常请记住readAsDataURL返回base64,它以
data:image/jpeg开头;base64,
这意味着您必须使用类似于
$data=explode(“,”,$\u POST['data'],2)的东西;echo base64_解码($data[1])
获取原始图像数据。