0
我試圖從我的Android應用程序與Loopj庫上傳圖像到服務器。在服務器端,我使用Codeigniter和文件上傳庫。但Codeigniter總是給我這個錯誤,即使我嘗試了允許的擴展。Loopj庫不能與Codeigniter文件上傳
The file type you are attempting to upload is not allowed
這是我的圖片上傳代碼
public void post_image() throws JSONException
{
RequestParams params = new RequestParams();
params.put("id_objek", id_objek);
params.put("id_user",id_user);
File myFile = new File(url_gambar);
try {
params.put("user_file", myFile);
} catch(FileNotFoundException e) {}
ApiRequest.post(url_gambar, params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// If the response is JSONObject instead of expected JSONArray
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray res) {
try {
JSONObject obj = res.getJSONObject(0);
String status = obj.getString("status");
String message = obj.getString("message");
if(status=="1"){
Toast.makeText(getApplication(),"Sukses:"+message,Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplication(),"Terjadi kesalahan:"+message,Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
這是在服務器端我的文件上傳代碼
if (empty($_FILES['user_file']['name'])) {
echo '['.json_encode(array(
'status'=>"0",
'message'=>'Gambar kosong'
)).']';
}else{
$info=null;
$config['upload_path'] = './images/gallery';
$config['allowed_types'] = 'gif|jpg|jpeg|png|jpeg|bmp';
$config['max_size'] = '5000';
$config['max_width'] = '5000';
$config['max_height'] = '2000';
$config['remove_spaces'] = 'true';
$this->load->library('upload');
$this->upload->initialize($config);
if (!$this->upload->do_upload('user_file')) {
echo '['.json_encode(array(
'status'=>"0",
'message'=>$this->upload->display_errors().'-'.$_FILES['user_file']['name']
)).']';
} else {
$info = $this->upload->data();
$thumb_config['image_library'] = 'gd2';
$thumb_config['source_image'] = $info['full_path'];
$thumb_config['create_thumb'] = TRUE;
$thumb_config['maintain_ratio'] = TRUE;
$thumb_config['width'] = 600;
$thumb_config['height'] = 600;
$this->load->library('image_lib');
$this->image_lib->initialize($thumb_config);
$this->image_lib->resize();
if ($nama_gambar == null)
$nama_gambar = $info['file_name'];
echo '['.json_encode(array(
'status'=>"1",
'message'=>$nama_gambar
)).']';
}
}
任何幫助或建議將不勝感激!