Codeigniter模块化HMVC扩展 - 无法上传文件

时间:2014-10-27 20:11:52

标签: codeigniter file-upload hmvc

我遇到按表单上传文件的问题。每次我尝试,我都会收到错误“文件类型不允许”。我正在使用HMVC模块化扩展,我的控制器扩展了MX_Controller。

我已经尝试从我的表单视图中获取$ var_dump($ _ FILES)并且结果很好,但是当我尝试在控制器中使用方法do_upload()时它不起作用。

有没有人有任何想法?这是控制器:

Class Store_data extends MX_Controller

{

function __construct()
{
    parent::__construct();
}

function upload_pic()
{
    //$data['item_id'] = $item_id;
    $template = "bootstrap_theme";
    //$current_url = current_url();
    //$data['form_location'] = $current_url;
    $data['view_file'] = "upload_pic";
    $this->load->module('template');
    $this->template->$template($data);
}

function do_upload()
{
    //var_dump($_FILES);
    $config['upload_path'] = './images/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '10000';
    $config['max_width']  = '4024';
    $config['max_height']  = '4768';
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->initialize($config);

    if ( ! $this->upload->do_upload())
    {
        $data['error'] = $this->upload->display_errors();
        $template = "bootstrap_theme";

        $data['view_file'] = "upload_pic";
        $this->load->module('template');
        $this->template->$template($data);
    }
    else
    {
        $data['upload_data'] = $this->upload->data();
        $template = "bootstrap_theme";
        $data['view_file'] = "upload_success";
        $this->load->module('template');
        $this->template->$template($data);
    }
}

以下是上传表单视图:

<?php echo $error;?>
<?php echo form_open_multipart('store_data/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。 我必须取消注释php.ini中的 extension = php_fileinfo.dll comment; extension = php_mime_magic.dll

非常感谢