php - 在 Codeigniter 中超过最大文件大小时不显示错误消息

标签 php codeigniter file-upload

我有一个可以上传图片和视频文件的表单。我在 php.ini

中设置了以下内容
post_max_size = 10M
upload_max_filesize = 10M

现在的问题是,如果上传的视频文件不是允许的类型,它会完美显示相应的错误。但是当我尝试上传更大尺寸 (23MB) 的视频时,它没有显示文件大小错误。下面给出的是我上传视频和图像的 Controller 代码(我正在使用文件上传类)。

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');
            }
        }
    }

谁能帮我解决这个问题?

在此先感谢您的帮助。

最佳答案

珍妮

请将下面的代码放在 index.php 中,这样你就可以得到错误

<?php 
error_reporting(E_ALL);
ini_set('display_errors',1);
?>

关于php - 在 Codeigniter 中超过最大文件大小时不显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602884/

相关文章:

php - laravel 两列代表一张表

PHP输出带有变量的字符串?

php - Codeigniter 不会加载语言

activerecord - 如何在codeigniter事件记录中使用select插入记录

node.js - 通过 file.createWriteStream() 流式传输到 GCP 时,获取 ESOCKETTIMEOUT、ECONNRESET 或套接字挂起大文件

php - 动画在登录时运行一次 - jQuery

javascript - 我如何知道服务器上数据库的主机名是什么

javascript - PHP 使用 javascript (codeigniter) 以动态形式进入数据库

php - 将图像上传到文件夹并获取其路径名

grails - 如何从 Grails 中上传的文件中获取字节 (byte[])