0

我遇到了一个没有错误消息的问题。我不知道为什么会这样。我的代码在本地主机上 100% 工作。但是当我将代码上传到实时共享主机时,上传过程后没有任何反应。我正在使用 codeigniter 3。这是我的 html 代码:

                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <form method="post" enctype="multipart/form-data">
                                <div class="modal-header bg-dark">
                                    <h5 class="modal-title">Edit Gambar Profil</h5>
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                </div>
                                <div class="modal-body text-center">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="alert alert-warning">
                                                Sebelum melanjutkan, pastikan Foto Profil yang Anda upload sudah tepat. Hanya berkas <b>JPG</b> dan <b>PNG</b> yang diperbolehkan. Maksimal ukuran berkas <b>2 MB</b>.
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <input type="file" class="form-control-uniform-custom" name="gambar" accept="image/*" id="upload" required>
                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <center>
                                            <div id="upload-demo" style="width:350px"></div>
                                            <div id="upload-demo-i"></div>
                                            </center>
                                        </div>
                                    </div>
                                    
                                    
                                </div>

                                <div class="modal-footer" id="upload_footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    <button class="btn bg-dark upload-result"><i class="icon-check pr-2"></i> Set Gambar Profil</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

这是我的 javascript 代码:

<script>
        $("#upload-demo").hide();
        $("#upload_footer").hide();
        
        //Mulai crop Image
        $uploadCrop = $('#upload-demo').croppie({
            enableExif: true,
            viewport: {
                width: 320,
                height: 320,
                //type: 'circle'
            },
            boundary: {
                width: 350,
                height: 350
            }
        });

        $('#upload').on('change', function () {
            $("#upload-demo").show();
            $("#upload_footer").show();
            var reader = new FileReader();
            reader.onload = function (e) {
                $uploadCrop.croppie('bind', {
                    url: e.target.result
                }).then(function(){
                    console.log('jQuery bind complete');
                });
            }
            reader.readAsDataURL(this.files[0]);
        });

        $('.upload-result').on('click', function (ev) {
            $uploadCrop.croppie('result', {
                type: 'canvas',
                size: 'viewport'
            }).then(function (resp) {
                $.ajax({
                    url: "<?php echo base_url('profil/postfotoprofil');?>",
                    type: "POST",
                    data: {"image":resp, "no_register" : "<?php echo sesuser('no_register');?>"},
                    success: function (data) {
                        console.log(data);
                        html = '<img src="' + resp + '" />';
                        $("#upload-demo-i").html(html);
                    }
                });
            });
        });
        //Akhir Crop image
    </script>

这是我发布的 ajax url 控制器:

public function postfotoprofil()
    {
        header("Access-Control-Allow-Headers: Authorization, Content-Type");
        header("Access-Control-Allow-Origin: *");
        $post = $this->input->post();
        $data = $post['image'];
        list($type, $data) = explode(';', $data);
        list(, $data)      = explode(',', $data);
        $data = base64_decode($data);
        $imageName = $post['no_register'].'.png';
        unlink('sekolah_berkas/user/'.$imageName);
        if(file_put_contents('sekolah_berkas/user/'.$imageName, $data)){
            $post_data      = array(
                "gambar"        => $imageName
            );
            $hajar  = $this->db->update("pengguna", $post_data, array("no_register" => $post['no_register']));
            if($hajar){
                $this->session->set_flashdata('pesen', '<script>sukses("proses");</script>');
            }else{
                $this->session->set_flashdata('pesen', '<script>gagal("proses");</script>');
            }
        }else{
            $this->session->set_flashdata('pesen', '<script>gagal("proses");</script>');
        }
        redirect(base_url("profil"));
    }

任何人都知道这件事,请帮助。

问题解决了

好的,伙计们...非常感谢您回复我的帖子。问题仅在提交按钮上。我将我的代码更改为:

<button class="btn bg-dark upload-result"><i class="icon-check pr-2"></i> Set Gambar Profil</button>

变成这样:

<a class="btn bg-dark upload-result"><i class="icon-check pr-2"></i> Set Gambar Profil</a>

问题解决了。使用(按钮)语法,您将立即提交给服务器。因此,您在提交时没有太多时间。然后我将其更改为语法(a)并真正解决了我的问题。看起来像小问题,没有错误信息你会头疼。

4

0 回答 0