我需要上传从安卓应用接收到的base64编码图像。我正在使用php 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();
}
}
我遇到了“您没有选择要上传的文件”错误提示。
感谢您的时间。
$this->file_name = $this->_prep_filename($_FILES[$field]['name']);
,这段代码是我在MY_Upload类中复制并粘贴的do_upload函数。Array ( [userfile] => Array ( [tmp_name] => C:\Windows\Temp\and15BC.tmp [size] => 354129 [error] => 0 [type] => image/png ) )
。$_FILES
中的“name”键,已经更新了示例,这应该可以修复两个错误。 - complex857$this->upload
实例的类名来检查它是否工作。print get_class($this->upload);
应该显示MY_upload
。 - complex857