上载文件||不允许您尝试上载的文件类型



在将视频存储到服务器时遇到问题。我已经更改了mimes.php中所有可能的类型,但问题仍然是我的代码 控制器

public function frontsliderAdd()
{
if ($this->session->userdata('admin_logged_in') != TRUE) {
redirect(base_url() . 'admin/login');
}
$data['active'] = 'frontslider';
if (isset($_POST['addgallery'])) {
$this->form_validation->set_rules('title', 'Banner Title', 'trim|required');
$this->form_validation->set_rules('video_url', 'Video Link', 'trim|required');
if ($_FILES["video_upload"]['name'] == '') {
$this->form_validation->set_rules('image_upload', 'Image', 'required');
}
if ($this->form_validation->run() == TRUE) {
if ($_FILES["video_upload"]['name']) {
$config['upload_path'] = './public/uploads/banner_images';
$config['allowed_types'] = 'jpg|png|jpeg|gif|mp4|avi|mov';
//$this->load->library('upload', $config);
$config['max_size'] = '0';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('video_upload')) {
$error_msg = $this->upload->display_errors();
} else {
$data['video'] = $this->upload->data();
}
}
$data['title'] = $this->input->post('title');
$data['video_url'] = $this->input->post('video_url');
$this->load->model('AdminModel');
$this->AdminModel->saveGallery($data);
}
}
$data['sidebar'] = $this->load->view('admin/sidebar', NULL, TRUE);
$this->load->view('admin/header');
$this->load->view('admin/frontslideradd', $data);
$this->load->view('admin/footer');
}

型号

public function saveGallery($data)
{
$array = array(
'title' => $data['title'],
'video' => $data['video']['file_name'],
'video_url' => $data['video_url']
);
$this->db->insert('front_slider', $array);
}

查看添加

<div class="form-group">
<label for="image_upload">Upload Video</label>
<input type="file" class="form-control" id="video_upload" name="video_upload">
<span class="help-block" style="color: red;"><?php echo form_error('video_upload') ?></span>
</div>

模拟

'3gp'   =>  array('video/3gp', 'video/3gpp'),
'mp4'   =>  'video/mp4',

它没有错误,但成功地将除视频外的其他数据传递到服务器请提前更正,thanx

您正在将上传数据存储在中

$data['image'] = $this->upload->data();

并分配了错误的密钥

'video' => $data['video']['file_name'] // Here is your problem 

您应该按照以下更改密钥

'video' => $data['image']['file_name']

希望这有助于

当文件上传中出现错误时停止以获得准确的错误

if (!$this->upload->do_upload('video_upload')) {
$error_msg = $this->upload->display_errors(); // Make exit here 
print_r($error_msg);
exit;
} else {
$data['video'] = $this->upload->data(); 
$data['title'] = $this->input->post('title');
$data['video_url'] = $this->input->post('video_url');
$this->load->model('AdminModel');
$this->AdminModel->saveGallery($data)
}

相关内容

  • 没有找到相关文章