代码点火器表单发送文件空


codeigniter form send file null

我尝试以这种方式使用codeigniter以表单形式发送图像:

<?php echo form_open_multipart('noticia/inserir', 'id="form-pessoas"'); ?>
<label for="titulo">Título:</label><br/>
<input type="text" name="titulo" value="<?php echo set_value('titulo'); ?>"/>
<div class="error"><?php echo form_error('resumo'); ?></div>
<label for="resumo">Resumo:</label><br/>
<input type="text" name="resumo" value="<?php echo set_value('resumo'); ?>"/>
<div class="error"><?php echo form_error('resumo'); ?></div>
<label for="descricao">Descrição:</label><br/>
<input type="text" name="descricao" value="<?php echo set_value('descricao'); ?>"/>
<div class="error"><?php echo form_error('descricao'); ?></div>
<label for="data">Data</label><br/>
<input type="text" name="data" value="<?php echo set_value('data'); ?>"/>
<div class="error"><?php echo form_error('data'); ?></div>
<label for="Foto">Foto:</label>
<input type="file" name="foto" id="foto" size="20" value="<?php echo set_value('foto'); ?>"/>
<input type="submit" name="cadastrar" value="Cadastrar" />
<?php echo form_close(); ?>

但输入文件发送空。

我的控制器:

function inserir()
{
    $this->load->library('form_validation');
    $this->load->helper('form');
    $this->load->helper('url');

    $this->form_validation->set_error_delimiters('<span>', '</span>');

    $this->form_validation->set_rules('titulo', 'Titulo', 'required|max_length[60]');
    $this->form_validation->set_rules('resumo', 'Resumo', 'required|max_length[100]');
    $this->form_validation->set_rules('descricao', 'Descrição', 'required|max_length[100]');
    //$this->form_validation->set_rules('data', 'Data', 'required');

    if ($this->form_validation->run() === FALSE) {
        $this->index();
    } else {
        $data['ds_titulo'] = $this->input->post('titulo');
        $data['ds_resumo'] = $this->input->post('resumo');
        $data['ds_noticia'] = $this->input->post('descricao');
        $data['ds_foto'] = $this->input->post('foto');
        //$data['data'] = $this->input->post('data');
        var_dump($this->input->post('foto'));exit;
        $this->upload($data);

        if ($this->model->inserir($data)) {
            redirect('noticia');
        } else {
            log_message('error', 'Erro ao inserir a noticia.');
        }
    }
}

  function upload($data){
    var_dump($data);exit;
    $this->load->helper('form');
    $this->load->helper('url');

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload($data['foto']))
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('cadastro-noticia', $error);
    }
    else
    {
        return true;

    }
}

需要获取图像文件并上传,然后将数据记录在数据库中,但问题从通过表单发送数据开始,有人帮忙吗?谢谢。

 var_dump($_FILES['foto']);exit;

和信息 您不能通过任何内容设置文件输入值。

<input type="file" name="foto" id="foto" size="20" value="<?php echo set_value('foto'); ?>"/>

所以这里值属性是没有用的... :)

<input type="file" name="foto" id="foto" size="20" />