我必須上傳我從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