0

I try to upload an image using android and php codeigniter as API.

I already have code but this always return error

Message: fopen(./a-kit-android/images/catat_stop_mesin) [ function.fopen]: failed to open stream: No such file or directory

this my codeigniter folder structure:

/a-kit-android/
    application/
    css/
    fonts/
    images/
         /catat_stop_mesin/
    js/ 
    system/
    user_guide/

here is my controller:

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";
        }       
}

and here is the model for accessing database

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;
}
Agustyan
  • 15
  • 2
  • 10
  • as the error says make sure that the path './a-kit-android/images/catat_stop_mesin' exists and accessible. – Mumen Yassin May 24 '16 at 09:08
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew May 27 '16 at 21:28

0 Answers0