简体   繁体   中英

getting 413 Request Entity Too Large error from ajax when posting base64 image to folder by file_put_contents

I m getting 413 Request Entity Too Large error while I sending my data by ajax I m getting converted base64 image encoded code...im passing that to My controller function in codeigniter..... that giving me error 413 Request Entity Too Large

my ajax code is bellow

    $('#save-image-php').click(function() {

        $.ajax({
                    type: "POST",              
                    url: php_directory_save,       
                    data: { base64_image: yourDesigner.getProductDataURL()},

                    success: function(data) {

                         if(parseInt(data) > 0) {
                            $( "#cart_pd" ).submit();

                            }

                    },
                    error: function() {
                        //alert('some error has occured...');
                    },
                    start: function() {
                        //alert('ajax has been started...');    
                    }
                });


});

my codeigniter controller function

    public function saveimage(){


        $base64_str = substr($this->input->post('base64_image'),strpos($this->input->post('base64_image'), ",")+1);

        $decoded = '';
        $decoded = base64_decode($base64_str);

        $png_name = '';
        $png_name = "product-".strtotime('now').".png";

        $png_url = '';
        $png_url = "uploaded_files/custom_image/".$png_name;


         $id = $this->product_model->save($png_name);
         $data = array('cust_id'=>$id); 
         $this->session->set_userdata($data);
         $result  = '';
         $result = file_put_contents($png_url, $decoded);

        if($id !=''){

            header('Content-Type: application/json');
            echo json_encode($id);

                   }

    }   

If you're running on nginx, this is the likely cause

In the nginx.conf

http {
    server {
        client_max_body_size 20M;
    }
}

Increase that to a more reasonable number and do some more testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM