2
votes

I m getting 413 Request Entity Too Large error while I sending my data by ajax I m getting converted base64 image encoded code...i m 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);

                   }

    }   
1
Exact same problem here! - Aozi
If you're on Apache, edit your apache php.ini file (avoid editing the one inside /php/ since that's for the CLI context of php): find and replace this entries as follows: post_max_size=20M and upload_max_filesize=20M. replace 20M (20 megabytes) for any value you feel comfortable with. - Luis Masuelli

1 Answers

0
votes

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.