调用未定义的方法CI_Upload :: do_multi_upload()Codeigniter

时间:2014-01-22 13:45:25

标签: codeigniter

我正在尝试使用此自定义库上传多个图像,但是我发现了do_multi_upload未定义的致命错误。         这是我的自定义库名称是my_upload.php 图书馆代码:

class My_Upload extends CI_Upload 
        {
            function  __construct($config = array())
            {
                parent::__construct($config);
            }

            public function do_multi_upload( $field, $return_info = TRUE, $filenames = NULL )
            {               
                if ( ! isset($_FILES[$field]))
                {
                    $this->set_error('upload_no_file_selected');
                    return FALSE;
                }


                foreach( $_FILES[$field]['name'] as $k => $n )
                {
                    if( empty( $n ) )
                    {
                        foreach( $_FILES[$field] as $kk => $f )
                        {
                            unset( $_FILES[$field][$kk][$k] );
                        }
                    }
                }


                if ( ! $this->validate_upload_path($field) )
                {

                    return FALSE;
                }


                if( is_array( $_FILES[$field] ) )
                {


                    foreach( $_FILES[$field]['name'] as $k => $file )
                    {

                        if ( ! is_uploaded_file($_FILES[$field]['tmp_name'][$k] ) )
                        {
                            $error = ( ! isset($_FILES[$field]['error'][$k])) ? 4 : $_FILES[$field]['error'][$k];

                            switch($error)
                            {
                                case 1: 
                                    $this->set_error('upload_file_exceeds_limit');
                                    break;
                                case 2: 
                                    $this->set_error('upload_file_exceeds_form_limit');
                                    break;
                                case 3: 
                                    $this->set_error('upload_file_partial');
                                    break;
                                case 4: 
                                    $this->set_error('upload_no_file_selected');
                                    break;
                                case 6: 
                                    $this->set_error('upload_no_temp_directory');
                                    break;
                                case 7: 
                                    $this->set_error('upload_unable_to_write_file');
                                    break;
                                case 8: 
                                    $this->set_error('upload_stopped_by_extension');
                                    break;
                                default :   $this->set_error('upload_no_file_selected');
                                    break;
                            }

                            return FALSE;
                        }


                        $this->file_temp = $_FILES[$field]['tmp_name'][$k];
                        $this->file_size = $_FILES[$field]['size'][$k];
                        $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type'][$k]);
                        $this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));

                        if(empty($filenames))
                        {
                            $this->file_name = $this->_prep_filename($_FILES[$field]['name'][$k]);                  
                        }
                        else
                        {
                            $this->file_name = $this->_prep_filename($filenames[$k]);
                        }

                        $this->file_ext  = $this->get_extension($this->file_name);
                        $this->client_name = $this->file_name;


                        if ( ! $this->is_allowed_filetype())
                        {
                            $this->set_error('upload_invalid_filetype');
                            return FALSE;
                        }

new name and type is allowed
                        if ($this->_file_name_override != '')
                        {
                            $this->file_name = $this->_prep_filename($this->_file_name_override);

file_name config item, use the uploaded one
                            if (strpos($this->_file_name_override, '.') === FALSE)
                            {
                                $this->file_name .= $this->file_ext;
                            }


                            else
                            {
                                $this->file_ext  = $this->get_extension($this->_file_name_override);
                            }

                            if ( ! $this->is_allowed_filetype(TRUE))
                            {
                                $this->set_error('upload_invalid_filetype');
                                return FALSE;
                            }
                        }


                        if ($this->file_size > 0)
                        {
                            $this->file_size = round($this->file_size/1024, 2);
                        }


                        if ( ! $this->is_allowed_filesize())
                        {
                            $this->set_error('upload_invalid_filesize');
                            return FALSE;
                        }

size?

                        if ( ! $this->is_allowed_dimensions())
                        {
                            $this->set_error('upload_invalid_dimensions');
                            return FALSE;
                        }


                        $this->file_name = $this->clean_file_name($this->file_name);


                        if ($this->max_filename > 0)
                        {
                            $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
                        }


                        if ($this->remove_spaces == TRUE)
                        {
                            $this->file_name = preg_replace("/\s+/", "_", $this->file_name);
                        }


                        $this->orig_name = $this->file_name;

                        if ($this->overwrite == FALSE)
                        {
                            $this->file_name = $this->set_filename($this->upload_path, $this->file_name);

                            if ($this->file_name === FALSE)
                            {
                                return FALSE;
                            }
                        }


                        if ($this->xss_clean)
                        {
                            if ($this->do_xss_clean() === FALSE)
                            {
                                $this->set_error('upload_unable_to_write_file');
                                return FALSE;
                            }
                        }


                        if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name))
                        {
                            if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
                            {
                                $this->set_error('upload_destination_error');
                                return FALSE;
                            }
                        }

                        $this->set_image_properties($this->upload_path.$this->file_name);


                        if( $return_info === TRUE )
                        {
                            $return_value[$k] = $this->data();
                        }
                        else
                        {
                            $return_value = TRUE;
                        }
                    }
                    return $return_value;
                }
                else
                {
                    $upload = self::do_upload();
                    return $upload;
                }
            }
        }



        Controller code to call multi upload function:


    $UploadConfig['max_size']           = '1024';       
    $UploadConfig['allowed_types']      = 'jpg|JPG|jpeg|JPEG|png|PNG';
    $UploadConfig['overwrite']          = FALSE;
    $UploadConfig['remove_spaces']      = TRUE;

        $this->load->library('upload', $UploadConfig);


        $this->upload->do_multi_upload('imagename', TRUE, $numberofimage);  

0 个答案:

没有答案