konda rakhee konda rakhee - 1 month ago 8
PHP Question

how to upload video and audio file and save folder in codeigniter

<?php
public function videoupld()
{
$this->load->helper('string');
$config['upload_path'] = 'assets/upload/video'; # check path is correct
$config['max_size'] = '102400000';
$config['allowed_types'] = 'mp4'; # add video extenstion on here
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$video_name =$_FILES['video_image']['name'];`
$config['file_name'] = $video_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('video_image'))
{
echo 'fail';
return;
//redirect('Admin/video_upload');
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
$url = 'assets/upload/video'.$video_name;
$this->Admin_model->videoupld($url);
redirect('Admin/video_upload');
}
}
?>


model

public function videoupld($url)
{
$title = $this->input->post('video_image');
//$details = $this->input->post('details');
//$type = $this->input->post('gallery');
$data = array(
'title' => $title,
'url' => $url,
//'category' => $type`
);
$this->db->insert('videoss', $data);
}

Answer

$uploaded = $this -> upload -> do_upload('video_image');

//here you will receive the object that you uploaded

// you will test if the file exist if yes the variable $file will recieve the full path if ($uploaded) { if ($data['file_ppt'] != '') {

                $file = 'uploads/ppt/' . $data['file_ppt']; //full path


                if (file_exists($file)) {
                    unlink($file);
                }
            }
        }
     //if file uploaded
     //$save['file_ppt'] will have the name of the file uploaded
         if ($uploaded) {
        $file_ppt = $this -> upload -> data();
        $save['file_ppt'] = $file_ppt['file_name'];
           }
Comments