如何在codeigniter中上传base64encoded图像

时间:2011-11-02 07:04:14

标签: php codeigniter

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

这就是我在做什么 -

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

uploadPhoto功能是:

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

图片未上传。这是正确的方法吗?

1 个答案:

答案 0 :(得分:2)

当使用base64_decode解码大文件时,有报告称存在各种故障。您可以在此处查看有关问题的更多信息http://www.php.net/manual/en/function.base64-decode.php#105512

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

相关问题