如何上传视频和音频文件和保存文件夹在codeigniter


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');
        }    
    }        
?>

    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);          
    }
 $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'];
               }
           $uploaded = $this -> upload -> do_upload('video_image');


            if ($uploaded) {
                if ($data['file_ppt'] != '') {
                    $file = 'uploads/ppt/' . $data['file_ppt'];

                    if (file_exists($file)) {
                        unlink($file);
                    }
                }
            }
        if ($uploaded) {
            $file_ppt = $this -> upload -> data();
            $save['file_ppt'] = $file_ppt['file_name'];
        }

  $this->db->insert('videoss', $save);   

把这个放到视图中:
在控制器中:$names =";$name_array = array();

    if(isset($_FILES['file_ppt'])){
    $count = count($_FILES['file_ppt']['size']);
    }else{
    $count=0;
    }
    foreach($_FILES as $key=>$value)
    for($s=0; $s<=$count-1; $s++) {
    $_FILES['file_ppt']['name']=md5(time())."".$value['name'][$s];
    $_FILES['file_ppt']['type']    = $value['type'][$s];
    $_FILES['file_ppt']['tmp_name'] = $value['tmp_name'][$s];
    $_FILES['file_ppt']['error']       = $value['error'][$s];
    $_FILES['file_ppt']['size']    = $value['size'][$s];
            // $config['allowed_types'] = 'gif|jpg|png';
            $config['upload_path'] = 'uploads/messages';
            $config['allowed_types'] = '*';
            $config['max_size']    = '200000';
    $this->load->library('upload', $config);
    $uploaded = $this->upload->do_upload('file_ppt');
    $data = $this->upload->data();
    $names = $names.','.$_FILES['file_ppt']['name'];
            }
       if ($uploaded) {
            // $file_ppt = $this -> upload -> data();
            $save['file_ppt'] = $names;
            // print_r('file ppt'.$file_ppt['file_name']);
        }else {
            echo $this->upload->display_errors();
        }