我尝试使用android和php codeigniter作为API上传图像。
我已经有了代码,但这总是会返回错误
消息:fopen(./ a-kit-android / images / catat_stop_mesin)[ function.fopen]:无法打开流:没有这样的文件或目录
这是我的codeigniter文件夹结构:
/a-kit-android/
application/
css/
fonts/
images/
/catat_stop_mesin/
js/
system/
user_guide/
这是我的控制器:
function catat_data_mesin_stop(){
header('Content-type: bitmap; charset=utf-8');
$id_mesin = $this->input->post('id_mesin', TRUE);
$nama_image = $this->input->post('nama', TRUE);
$image_encoded = $this->input->post('image', TRUE);
$image_decoded = base64_decode($image_encoded);
//path image will be stored
$path = './a-kit-android/images/catat_stop_mesin';
//write the file
$file = fopen($path, 'w');
//Write the file to the folder
$is_written = fwrite($file, $image_decoded);
//Close the file
fclose($file);
IF (isset($_POST) && ($is_written > 0)){
$data = array(
'path_stop_mesin_bbm' => $nama_image)
);
header('Content-type: application/json');
echo json_encode($this->mod_a_kit->data_stop_mesin($id_mesin, $data));
}
ELSE{
echo "Nothing In post";
}
}
这是访问数据库的模型
function data_stop_mesin($id, $data)
{
$this->db->trans_start();
$this->db->set($data);
$this->db->where('id_mesin', $id);
$this->db->update('t_start_stop_mesin', $data);
$this->db->trans_complete();
if ($this->db->trans_status() === TRUE){
$response['status'] = 1;
$response['message'] = "Upload success";
}
else{
$response['status'] = 0;
$response['message'] = "Upload failed";
}
return $response;
}