我被困在这里..我正在尝试上传图片和视频,图片上传工作正常,但在上传视频时收到错误为“您尝试上传的文件类型不被允许”。我已经尝试了所有答案,但遗憾的是无法锻炼。有人可以帮我。我究竟做错了什么?感谢。
我的观点'主页':
<div style="margin-right: 17px;">
<label>Name:</label>
<input type="text" name="name" value="<?php echo set_value('name');?>">
<?php echo form_error('name','<div class="error">','</div>'); ?>
</div>
<div style="padding:20px 20px">
<label>Upload Image</label>
<input type="file" name="photo">
</div>
<div style="padding:5px 5px">
<label>Upload Video</label>
<input type="file" name="video">
</div>
<div style="padding:10px 10px">
<input type="submit" name="sumit" value="Submit">
</div>
</form>
我的控制器:
$this->form_validation->set_rules('name', 'Name', 'trim|required');
if(! $this->form_validation->run()){
$data['useradded'] = "";
}
else{
if(isset($_FILES['photo']['tmp_name'])){
$config['upload_path'] = "./uploads/complaints/";
$config['allowed_types'] = "jpg|png|gif";
$config['max_size'] = '2048';
$config['max_width'] = '0';
$config['max_height'] = '0';
$new_name = "photo_" . rand();
$config['file_name'] = $new_name;
$this->load->library('upload', $config);
if(! $this->upload->do_upload('photo')){
$data['error'] = array('error' => $this->upload->display_errors());
$photo_name = "";
}else{
$photo_name = $new_name;
}
}
if(isset($_FILES['video']['tmp_name'])){
$config['upload_path'] = "./uploads/complaints/videos/";
$config['allowed_types'] = "avi|flv|wmv|mpg|mpeg|mp3|mp4";
//$config['allowed_types'] = "video/x-msvideo|image/jpeg|video/mpeg|video/x-ms-wmv";
$config['max_size'] = '0';
$new_name = "video_" . rand();
$config['file_name'] = $new_name;
$this->load->library('upload', $config);
if(! $this->upload->do_upload('video')){
$data['error'] = array('error' => $this->upload->display_errors());
$video_name = "";
}else{
$video_name = $new_name;
}
}
$this->complaints_model->add_complaint($photo_name,$video_name);
$data['useradded'] = "New complaint added Successfully";
}
$this->load->view('home', $data);