简体   繁体   English

将图像编码到base64中无法正常工作

[英]encode image in to base64 not working properly

if ( ! $this->upload->do_upload('course_profile_image'))
        {

            error($this->upload->display_errors(),TRUE,400);
        }else{
            $data = array('upload_data' => $this->upload->data());
            $filename=$data['upload_data']['file_name'];
            $pathinfo = 'dist/img/courseimage/'.$filename;
            $filetype = pathinfo($pathinfo, PATHINFO_EXTENSION);
            $filecontent = file_get_contents($pathinfo);

            try{
                $base64=rtrim(base64_encode($filecontent)); 

            }catch(Exception $e){
                error($e,TRUE,855);


            }
            $image = 'data: '.mime_content_type($pathinfo).';base64,'.$base64;  

It's converting the image into the base64 but when large dimensions images uploaded it covets only half or some part of it. 它会将图像转换为base64,但是当上传大尺寸图像时,它只垂涎一半或一部分。 I am storing this base64 in to mysql database column type text. 我将这个base64存储到mysql数据库列类型文本中。

将您的数据库字段类型从text更改为mediumText,因为TEXT只有64 KiB的长度,因此它不存储您的完整基础64代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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