2

我正在创建上传功能,但我希望它成为更大功能的一部分,如下所示:

public function addGame() {
    // validation
    $this->load->library('form_validation');
    $this->form_validation->set_rules('title', 'Tytuł gry', 'required');
    $this->form_validation->set_rules('dsc', 'Opis gry', 'required');

    $data['title'] = 'Dodaj grę';

    $this->load->model('contrib_model');
    $this->load->model('games_model');

    // image upload
    $config['upload_path'] = './img/';

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

    if ($this->form_validation->run()) {
        $data['submit'] = $this->contrib_model->addGame($this->input->post()); //submits data
        if ( ! $this->upload->do_upload($this->input->post('cover')))
        {
            $error = array('error' => $this->upload->display_errors());
            print_r($error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            print_r($data);
        }
        $this->load->view('contribute/emptyPage', $data); //loads view
    } else {
        $data['genres'] = $this->games_model->Genres();
        $data['platforms'] = $this->games_model->Platforms();
        $data['developers'] = $this->games_model->Developers();

        $this->layout->view('contribute/addGame', $data); //loads view
    }
}

我的表格:

<li><input type="text" name="title" id="title" placeholder="Tytuł gry" class="required"></li>
<li><textarea name="dsc" id="dsc" cols="30" rows="10" placeholder="Opis gry" class="required"></textarea></li>
<li><input type="text" name="dsc_src" id="dsc_src" placeholder="Źródło opisu" class="required"></li>
<li><input class="required" type="text" name="reldate" id="reldate" placeholder="Data wydania (RRRR-MM-DD"></li>
<li><input type="file" name="cover" id="cover" class="required"></li>

我的问题是它说没有指定文件。我究竟做错了什么?

4

2 回答 2

2

你的if陈述实际上应该是

if ( ! $this->upload->do_upload('cover'))

代替

if ( ! $this->upload->do_upload($this->input->post('cover')))
于 2012-06-25T18:36:47.353 回答
0

我在全新的 WAMP 安装中遇到了类似的问题。原来,我的 php.ini 文件中的 HTTP 文件上传已关闭。所以请确保它已打开。

file_uploads = On
于 2013-03-01T12:17:17.420 回答