我面临的问题如下:
我在codeigniter中开发API,用于将上传图像转换为服务器的特定文件夹。当我检查邮递员工作正常。但是,当我检查Android应用程序不能正常工作。
请给我一些建议。
提前致谢。
我的代码如下:
public function updateimage_post() {
if(!$this->post('UserID')) {
$status = [
['status' => 400 , 'message' => 'UserID is required.'],
];
$this->response($status, REST_Controller::HTTP_BAD_REQUEST);
} else {
$this->db->where(array('ID' => $this->post('UserID')));
$db_result = $this->db->get('userregistration');
if ($db_result && $db_result->num_rows() > 0) {
if(isset($_FILES['ProfilePicture']['name'])) {
$info = pathinfo($_FILES['ProfilePicture']['name']);
$ext = $info['extension'];
if (($ext == "GIF" || $ext == "PNG" || $ext == "JPG" || $ext == "jpg" || $ext == 'gif' || $ext == 'png' || $ext == 'jpeg') && ($_FILES["ProfilePicture"]["type"] == "image/PNG" || $_FILES["ProfilePicture"]["type"] == "image/GIF" || $_FILES["ProfilePicture"]["type"] == "image/JPG" || $_FILES["ProfilePicture"]["type"] == "image/jpg" ||$_FILES["ProfilePicture"]["type"] == "image/jpeg" || $_FILES["ProfilePicture"]["type"] == 'image/gif' || $_FILES["ProfilePicture"]["type"] == 'image/png') && ($_FILES["ProfilePicture"]["size"] < 30485760)) {
$file = $info['filename'];
$filename = 'frontuser' . '_' . uniqid() . '.' . $ext;
$target = './uploads/frontusers/' . $filename;
$file = $_FILES['ProfilePicture']['tmp_name'];
if (move_uploaded_file($file, $target)) {
$data = array(
'ProfilePicture' => $filename,
'ModifiedOn' => date('Y-m-d H:m:s'),
);
$result = $this->db->update('userregistration', $data, array('ID' => $this->post('UserID')));
} else {
$status = ['status' => 201 , 'message' => 'Image not uploaded.'];
$this->response($status, REST_Controller::HTTP_OK);
}
} else {
$status = ['status' => 201 , 'message' => 'File is invalid.'];
$this->response($status, REST_Controller::HTTP_OK);
}
} else {
$status = ['status' => 201 , 'message' => 'Please Select image.'];
$this->response($status, REST_Controller::HTTP_OK);
}
if($result) {
$status = [
'status' => 200,
'message' => 'Profile Picture Update Successfully',
];
} else {
$status = [
'status' => 201,
'message' => 'Something went wrong !!',
];
}
$this->set_response($status, REST_Controller::HTTP_OK);
} else {
$status = [
'status' => 201,
'message' => 'UserID does not exist !!',
];
$this->set_response($status, REST_Controller::HTTP_OK);
}
}
}