Reputation: 3433
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?
Upvotes: 0
Views: 4850
Reputation: 88
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));
Upvotes: 2