大家好,我有一个文件可以上传视频到服务器但是什么时候 在我的localhost上测试,它工作得非常好,但是当我移动到 服务器,只创建了目录,但视频不是 上传。
所以下面的代码确实获得了任何文件类型(只有Permitted)并将它们转换为.flv文件,然后将它们上传到服务器,然后将名称存储到数据库中。
我面临的另一件事是,当我点击上传视频文件时, 它确实出现了成功消息,但没有报告错误
public function submit_file(){
$err_msgs ='';
if($this->input->post('submit')){
$this->form_validation->set_rules('course_id','search term','required');
$this->form_validation->set_rules('lesson_name','search term','required');
$this->form_validation->set_rules('file_name','search term','required');
$course_id =$this->input->post('course_id');
$lesson_name =$this->input->post('lesson_name');
$real_file_name =$this->input->post('file_name');
$course_name =$this->Course->get_course_name($course_id);
if($this->form_validation->run() == FALSE){
$data['alert'] ='<p class="alert alert-danger" role="alert">Some Filled Were Not filled</p>';
$this->session->set_flashdata('alert',$data['alert']);
redirect('Create_course/upload_lesson');
}else{
//create Dictory for course_name
$course_name_url =@ereg_replace(" ","_","$course_name");
$lesson_name_url =@ereg_replace(" ","_","$lesson_name");
@mkdir('__course_file/'.$course_name_url);
@mkdir('__course_file/'.$course_name_url.'/lesson');
@mkdir('__course_file/'.$course_name_url.'/lesson/'.$lesson_name_url);
$config['upload_path'] = './__course_file/'.$course_name_url.'/lesson/'.$lesson_name_url;
$config['allowed_types'] = 'mov|mpeg|mp3|avi|mp4|wmv|mpg';
$config['max_size']= '';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = TRUE;
$this->upload->initialize($config);
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {
// If there is any error
$err_msgs = '<p class="alert alert-danger" role="alert">'.$this->upload->display_errors().'</p>';
$this->session->set_flashdata('alert',$err_msgs);
}else{
//convert file to .flv extension
$data=array('upload_data' => $this->upload->data());
$video_path = $data['upload_data']['file_name'];
$directory_path = $data['upload_data']['file_path'];
$directory_path_full = $data['upload_data']['full_path'];
$file_name = $data['upload_data']['raw_name'];
// ffmpeg command to convert video
exec("ffmpeg -i ".$directory_path_full." ".$directory_path.$file_name.".flv");
// $file_name is same file name that is being uploaded but you can give your custom video name after converting So use something like myfile.flv.
$name = $this->upload->data('full_path');
unlink($name);
/// In the end update video name in DB
$file_path =$this->upload->data('full_path');
$file_name =$this->upload->data('raw_name').'.flv';
$insert =$this->Course->insert_lesson($course_name,$lesson_name,$file_path,$course_name_url,$lesson_name_url,$file_name,$real_file_name);
if($insert ==TRUE){
$data['alert'] ='<p class="alert alert-success" role="alert">Your Course Has been Created</p>';
$this->session->set_flashdata('alert',$data['alert']);
}else{
$data['alert'] ='<p class="alert alert-danger" role="alert">Database Busy, Could not Create Course, Pls Try Again Later!</p>';
$this->session->set_flashdata('alert',$data['alert']);
}
}
redirect('Create_course/upload_lesson');
}
}else{
$data['alert'] ='<p class="alert alert-danger" role="alert">Please use the form to submit file</p>';
$this->session->set_flashdata('alert',$data['alert']);
redirect('Create_course/upload_lesson');
}
}
这里的每件事都适用于我的localhost