如何在codeigniter中上传base64编码的图像
我有一个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;
}
}
}
图像没有上传。这是正确的方法吗?
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)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有报告称使用 base64_decode 解码大文件时会出现各种失败。您可以在此处查看有关问题的更多信息 http://www.php .net/manual/en/function.base64-decode.php#105512
我建议像这样分割字符串
$decodedstring=base64_decode(chunk_split($encodedstring));
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
I recommend splitting the string like this
$decodedstring=base64_decode(chunk_split($encodedstring));