通过PHP通过表单发送base64图像时,$ _ POST为空

时间:2019-03-29 21:23:42

标签: javascript php codeigniter

我有一个使用croppie的图像上传脚本,它会裁剪图像并生成一个base64字符串,我将其放入隐藏的输入中,并通过codeigniter和php发送到我拥有的服务器,一旦存在,我便解码并上传它,代码由于某些原因而有效,但是有一些图像在我将它们上传时,$ _ POST变为空并且服务器什么也没收到

我在线检查,似乎与post_max_size有关,并通过

进行了检查
std::vector <std::istream *>

它返回异常,但仅此而已,图像的长度不是那么长,并且我已将主机升级到可以的最大数量

    if ( !empty($_SERVER['CONTENT_LENGTH']) && empty($_POST) ){
        throw new Exception('PHP discarded POST data because of request   exceeding post_max_size, '.ini_get("upload_max_filesize"));
    } else {
        var_dump($_POST);
    }

但这并不能解决我的问题,我尝试对此问题进行更多研究,但无济于事

这是表格


    post_max_size                   128M
    suhosin.post.max_value_length   3000000
    suhosin.post.max_vars           3000000
    suhosin.request.max_vars    3000000
    upload_max_filesize             1G

裁剪脚本

    <?php                    
            echo form_open_multipart('disco/registrar');
            ?>
            <div class="col-md-12">            
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-plus-circle"></i> Crear un evento </h3>
                    </div>
                    <div class="panel-body">
                        <div>
                            <label for="titulo" class="col-md-4">
                                Nombre* :
                            </label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" id="titulo" name="titulo" placeholder="Digite un nombre" required
                                oninvalid="this.setCustomValidity('Por digite un nombre')"
                                oninput="setCustomValidity('')">
                            </div>  
                        </div>                  
                        <br>
                        <br>
                        <div>
                            <label for="descripcion" class="col-md-4">
                                Descripción* :
                            </label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" id="descripcion" name="dir" placeholder="Digite una dirección" required
                                oninvalid="this.setCustomValidity('Por digite una descripción')"
                                oninput="setCustomValidity('')">
                            </div>
                        </div>
                        <br>
                        <br>
                        <div>
                            <label for="extra" class="col-md-4">
                                Información adicional :
                            </label>
                            <div class="col-md-8">
                                <textarea class="form-control" id="extra" name="extra" placeholder="Digite la información adicional" rows="3">
                                </textarea>
                            </div>
                        </div>
                        <br>
                        <br>
                        <div>
                            <label for="date" class="col-md-4">
                                Seleccione hasta cuando estara disponible la promoción* :
                            </label>
                            <div class="col-md-8">      
                                <div class="form-group">                            
                                    <input type="text" class="form-control" name="date" id="date" required
                                    oninvalid="this.setCustomValidity('Por favor seleccione una fecha')"
                                    oninput="setCustomValidity('')">
                                </div>
                            </div>
                        </div>
                        <div>
                            <label for="logo" class="col-md-4">
                                Seleccione una imagen* :
                            </label>
                            <div class="col-md-8"> 
                                <div class="form-group">
                                    <input type="file" id="logo" name="logo" class="file">
                                </div>
                            </div>  
                        </div>              
                        <div class="row">
                            <div class="col-md-12">
                                <center>
                                    <div>
                                        <img src="" id="imgPlace" style="max-width: 100% !important;">
                                    </div>
                                </center>
                            </div>
                        </div>
                        <br>
                        <br>
                        <div>
                            <div class="col-md-12">
                                <h4>
                                    <p class="text-primary">Los campos marcados con * son obligatorios.</p>
                                </h4>
                                <?php 
                                if(null !== $this->session->flashdata('Error')){
                                    echo('<div class="alert alert-dismissable alert-danger col-md-12-">
                                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                                        <strong>El numero de preguntas no es número mayor que 0.</strong>
                                        </div>
                                        <br>');
                                }
                                ?>
                            </div>
                        </div>
                        <div>
                            <div class="col-md-4">
                            </div>
                            <div class="col-md-4">
                                <center>
                                    <input type="hidden" name="croppedData" id="croppedData" value="">
                                    <button class="btn btn-lg btn-primary" type="submit" name="btnquiz" id="btnquiz" >Registrar</button>
                                </center>
                            </div>
                            <div class="col-md-4">
                            </div>
                        </div>
                    </div>
                </div>      
            </form>

服务器

    function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#imgPlace').attr('src', e.target.result);
                    $('#imgPlace').css({
                        height: '100%'
                    });
                    var uploadCrop = $('#imgPlace').croppie({
                        enableExif: true,
                        viewport: {
                            width: 800,
                            height: 600
                        },
                        boundary: {
                            width: 1024,
                            height: 1024
                        },
                        update: function (data) {
                            uploadCrop.croppie('result', 'base64', 'viewport', 'png').then(function(newImg) {
                                $('#croppedData').val(newImg);
                                console.log(newImg);
                            });
                        }
                    });
                    uploadCrop.bind({
                        url: e.target.result,
                    });

                }

                reader.readAsDataURL(input.files[0]);

            }
        }

正如我在这段代码起作用之前所说的那样,但是有些图像将无法通过,例如this one

0 个答案:

没有答案