codeigniter项目的视频上传

时间:2015-10-09 07:02:42

标签: php codeigniter

我无法使用此控制器上传视频,但我已经编写了类似类型的控制器,可以成功上传图片,但我无法上传视频。这里附加的是控制器文件: -

        public function trail_itinerary($id = null)
    {
        if($this->userlib->isLoggedIn())
        {
            $error_no['trail_id1'] = $id;
            $user_id = $this->userlib->getId();
            $itinerary = $this->input->post('itinerary');
            $highlights = $this->input->post('highlights');
            $hotel_name = $this->input->post('hotel_name');
            $stay_description = $this->input->post('stay_description');
            $hotel_star_cat = $this->input->post('hotel_star_cat');
            $destination = $this->input->post('destination');
            $nights = $this->input->post('nights');
            $inclusions = $this->input->post('inclusions');
            $exclusions = $this->input->post('exclusions');
            $terms_conditions = $this->input->post('terms_conditions');
            $cancellation_policy = $this->input->post('cancellation_policy');

            //$upload_videos = picture of videos

            $email = $this->userlib->getEmail();

            $structure = 'application/views/upload/'.$email.'/'.$id;
            if(is_dir($structure))
            {
                $config['upload_path'] = $structure;
            }
            else
            {
                mkdir($structure);
                $config['upload_path'] = $structure;
            }   

            $config['allowed_types'] = 'gif|jpg|jpeg|png|doc|docx|ppt|pptx|pdf|txt|avi|mpeg|mp3|mp4|3gp';
            $config['max_size'] = '40000000';
            $this->load->library('upload', $config);
            $this->upload->initialize($config);

            $data['upload_data'] = '';
            if (!$this->upload->do_upload('upload_videos'))
            {
                $data = array('msg' => $this->upload->display_errors());
            }
            else
            {   
                $data = array('msg' => "Upload success!");
                $data = $this->upload->data();
                $upload_videos = $data['file_name'];
            }

            $this->form_validation->set_rules('itinerary', 'Itinerary', 'trim|required');
            $this->form_validation->set_rules('highlights', 'Highlights', 'trim|required');
            $this->form_validation->set_rules('hotel_name', 'Hotel Name', 'trim|required');
            $this->form_validation->set_rules('stay_description', 'Stay Description', 'trim|required');
            $this->form_validation->set_rules('hotel_star_cat', 'Hotel Star Category', 'trim|required');
            $this->form_validation->set_rules('destination', 'Hotel Location', 'trim|required');
            $this->form_validation->set_rules('nights', 'Nights at hotel', 'trim|required');
            $this->form_validation->set_rules('inclusions', 'Inclusions', 'trim|required');
            $this->form_validation->set_rules('exclusions', 'Exclusions', 'trim|required');
            $this->form_validation->set_rules('terms_conditions', 'Terms & Conditions', 'trim|required');
            $this->form_validation->set_rules('cancellation_policy', 'Cancellation Policy', 'trim|required');

            if($this->form_validation->run() == FALSE)
            {
                $this->load->view('trail_itinerary',$error_no);
            }
            else
            {
                $data3['trail_id2']=$this->seller_store_model->trail_itinerary($user_id, $id, $itinerary, $highlights, $hotel_name, $stay_description, $hotel_star_cat, $destination, $nights, $inclusions, $exclusions, $terms_conditions, $cancellation_policy);
                if($this->input->post('review')=="Review")
                {
                    $this->load->view('edit_trail_basic_info', $data3);
                }
                elseif($this->input->post('submit')=="Submit")
                {
                    redirect('/seller_store');  //later on remove the functionality
                } //else unsetting of the data
            }
        }   
        else
        {
            echo "User not authorised";
        }
    }

我已经在config / mimes.php和php.ini文件中完成了所需的更改。

1 个答案:

答案 0 :(得分:0)

config/mimes.php

添加此

'mp4' => array('video/mp4', 'application/octet-stream'),

默认为'video/mp4'。同时添加此部分'application/octet-stream'