我正在创建上传功能,但我希望它成为更大功能的一部分,如下所示:
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>
我的问题是它说没有指定文件。我究竟做错了什么?