【发布时间】:2014-05-01 10:11:56
【问题描述】:
我有一个可以同时上传图片和视频文件的表单。我在 php.ini
中设置了以下内容post_max_size = 10M
upload_max_filesize = 10M
现在的问题是,如果上传的视频文件不是允许的类型,则完美显示相应的错误。但是当我尝试上传更大尺寸(23MB)的视频时,它没有显示文件大小错误。下面给出的是我上传视频和图像的控制器代码(我正在使用文件上传类)。
VideoController 的代码:
function index()
{
$userid=$this->tank_auth->get_user_id();
if (empty($_FILES['thumb_image']['name']))
{
$this->form_validation->set_rules('thumb_image', 'Thumb Image', 'required|max_length[255]');
}
if (empty($_FILES['video']['name']))
{
$this->form_validation->set_rules('video', 'Video', 'required');
}
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$data['page']='video/upload';
if ($this->form_validation->run() == FALSE) // validation hasn't been passed
{
$this->load->view('layout/template',$data);
}
else // passed validation proceed to post success logic
{
$file=$_FILES['video']['name'];
$thumbfile=$_FILES['thumb_image']['name'];
$form_data = array(
'videolink' => time().$file,
'videothumbnail' => time().$thumbfile,
'uploaderid' => $userid,
);
$config['upload_path'] = './secure/';
$config['allowed_types'] = 'mpeg|mp4|mpg|mpe|qt|mov|avi|movie|wmv|flv|3gp|mkv|dv|m4u|m4v|mxu|rv';
$config['max_size'] = '10240';
$extn = end(explode(".", $_FILES['video']['name']));
$config['file_name'] = time().$_FILES['video']['name'].'.'.$extn;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$data['upload_data'] = '';
if (!$this->upload->do_upload('video'))
{
$data['msg'] = $this->upload->display_errors(); // this is not throwing error
$this->load->view('layout/template',$data);
}
else
{
$data['upload_data'] = $this->upload->data();
if($_FILES['thumb_image']['name']!="")
{
$config1['upload_path'] = './secure/';
$ext = end(explode(".", $_FILES['thumb_image']['name']));
$config1['file_name'] = time().$_FILES['thumb_image']['name'].'.'.$ext;
$config1['allowed_types'] = 'jpg|png|jpeg|gif|bmp|jpe|tiff|tif';
$this->load->library('upload', $config1);
$this->upload->initialize($config1);
if (!$this->upload->do_upload('thumb_image'))
{
$data['msg'] = $this->upload->display_errors();
$this->load->view('layout/template',$data);
}
}
if ($this->Video_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
{
$this->session->set_flashdata('msgresult', 'Successfully uploaded the video !');
}
else
{
$this->session->set_flashdata('msgresult', 'Please try again. Some error occur during uploading.');
}
$data['errors'] = false;
$data['success'] = true;
redirect('video/upload');
}
}
}
谁能帮我解决这个问题?
提前感谢您的帮助。
【问题讨论】:
-
如果你做一个
var_dump($this->upload->display_errors());你会得到什么? -
它没有显示任何东西...
标签: php codeigniter file-upload