簡體   English   中英

通過file_put_contents將base64圖像發布到文件夾時,從ajax得到413請求實體太大錯誤

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

我通過Ajax發送數據時遇到413 Request Entity Too Large錯誤,得到轉換的base64圖像編碼的代碼... im將其傳遞給Codeigniter中的我的控制器函數.....這給了我413 Request Entity Too Large的錯誤

我的ajax代碼是波紋管

    $('#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...');    
                    }
                });


});

我的codeigniter控制器功能

    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);

                   }

    }   

如果您在Nginx上運行,這可能是原因

在nginx.conf中

http {
    server {
        client_max_body_size 20M;
    }
}

將其增加到一個更合理的數字並進行更多測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM