我必须上传我从android应用程序接收的base64编码图像。我使用php codeigniter框架。 在搜索论坛时,此链接How to upload base64encoded image in codeigniter的问题与我的相同,但解决方案不适合我。无法使用Codeigniter上传base64编码图像
这里是我写的代码:
private function _save_image() {
$image = base64_decode($_POST['imageString']);
#setting the configuration values for saving the image
$config['upload_path'] = FCPATH . 'path_to_image_folder';
$config['file_name'] = 'my_image'.$_POST['imageType'];
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2048';
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if($this->upload->do_upload($image)) {
$arr_image_info = $this->upload->data();
return ($arr_image_info['full_path']);
}
else {
echo $this->upload->display_errors();
die();
}
}
我收到“您没有选择要上传的文件”
感谢您的时间。
嗨,谢谢你的回复。我按照您的指导进行了更改,但出现以下错误: 1。'$ this-> file_name = $ this - > _ prep_filename($ _ FILES [$ field] ['name'])的行号86处的未定义索引; '在我在MY_Upload类中复制的do_upload函数中。 2.您正试图上传的文件类型是不允许的。这是print_r'Array([userfile] => Array([tmp_name] => C:\ Windows \ Temp \ and15BC.tmp [size] => 354129 [error] => 0 [type] => image/png))' – Parth 2012-07-20 13:53:28
我忘记了'$ _FILES'中的'name'键,更新了这个例子,它应该修复这两个错误。 – complex857 2012-07-20 14:07:47
嗨非常感谢你。它的工作现在 – Parth 2012-07-20 19:29:17