Skip to main content

API ( service ) Image or Video Upload

## SAVE  VIDEO
public function uploadmedia()
{

$target_path = "assets/uploads/";

$target_path = $target_path . basename($_FILES['file']['name']);

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
$this->api_return(
[ 'status' => true,
   'result' => 'uploaded success'
], 200);


}
else{
$this->api_return(
[ 'status' => false,
   'result' => 'failed'
], 20);
}




}


## SAVE FILE IMAGE OR VIDEO
public function savefile()
{

$filetype = $_FILES['file']['type'];

if (strpos($filetype, 'image') !== false) {
$type = 'image';
}

if (strpos($filetype, 'video') !== false) {
$type = 'video';
}


        $filename = trim($_FILES['file']['name']);
// $userid = trim($this->input->get('userid'));     

$target_path = "assets/uploads/";

$target_path = $target_path . basename($_FILES['file']['name']);

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
$insertdata = array(
                    // 'userid' => $userid,
                    'filename' => $filename,
                    'type' => $type,
                    'date' => date('Y-m-d h:i:s'),                   

                );

        $insert = $this->user_model->INSERTDATA('library', $insertdata);

            if($insert){
           
            $this->api_return(
            [ 'status' => true,
               'result' => $insert
            ], 200);

            }
            else
            {
            $this->api_return(
            [ 'status' => false,
               'result' => 'failed to insert data'
            ], 400);

            }
} else {
$this->api_return(
[ 'status' => false,
'result' => 'failed to upload file'
], 400);
}

}

Comments