如何在codeigniter中上传base64编码的图像 [英] How to upload base64encoded image in codeigniter

查看:419
本文介绍了如何在codeigniter中上传base64编码的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个base64编码图像字符串 $ imgcode 这是一个base64编码图像,我想使用codeigniter上传它。

I have a base64 encoded image string $imgcode which is a base64 encoded image, and I want to upload it using codeigniter.

这是我在做什么 -

Here is what i am doing -

$this->Photo_model->uploadPhoto($userdir,base64_decode($imgCode)

uploadPhoto函数是这样:

The uploadPhoto function is this:

public function uploadPhoto($path,$img){

    //echo $img;
    //echo $path;

    $config['upload_path'] = $path;
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);

    if(!$this->upload->do_upload($img)){
        return FALSE;  
    }
    else{ 
        $fInfo = $this->upload->data();
        $this->createThumbnail($fInfo['file_name'],$fInfo['file_path']);  

        $this->load->model('Photo_model');
        if($this->Photo_model->savePhotoInfo($fInfo['file_name'],$path)){
            return true;
        }
        else{
            return false;
        }
    }
}

。这是正确的方法吗?

The image is not getting uploaded. Is this the correct way?

推荐答案

当使用base64_decode解码大文件时,您可以在这里查看更多有关问题的资讯 http://www.php .net / manual / en / function.base64-decode.php#105512

There have been reports of various kinds of failures when base64_decode is used to decode large files. You can see more about the problems here http://www.php.net/manual/en/function.base64-decode.php#105512

我建议像这样分割字符串
$ decodedstring = base64_decode(chunk_split($ encodedstring));

I recommend splitting the string like this $decodedstring=base64_decode(chunk_split($encodedstring));

这篇关于如何在codeigniter中上传base64编码的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆