我正在创建上传功能,但我希望它成为更大功能的一部分,如下所示:
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>
我的问题是它说没有指定文件。我做错了什么?
答案 0 :(得分:2)
您的if
声明实际应该是
if ( ! $this->upload->do_upload('cover'))
而不是
if ( ! $this->upload->do_upload($this->input->post('cover')))
答案 1 :(得分:0)
我在新的WAMP安装上遇到了类似的问题。原来在我的php.ini文件中关闭了HTTP文件上传。所以要确保它已经开启。
file_uploads = On