2

I'm creating upload functionality, but I want it to be a part of a bigger function, like this:

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
    }
}

And my form:

<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>

My problem is that it says that there is no file specified. What am I doing wrong?

4
  • What line is throwing that error? Have you been able to debug? Commented Jun 25, 2012 at 18:24
  • The only error is "You did not select a file to upload.". Which I did. Commented Jun 25, 2012 at 18:26
  • Is the form open tag something like this: <?php echo form_open_multipart('yourcontroller/addGame');?>? Commented Jun 25, 2012 at 18:32
  • Yes, <?php echo form_open_multipart('contribute/addGame', 'id="addGame"'); ?>. Form itself works - values are added to database, only images aren't working. Commented Jun 25, 2012 at 18:33

2 Answers 2

2

Your if statement should actually read

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

instead of

if ( ! $this->upload->do_upload($this->input->post('cover')))
Sign up to request clarification or add additional context in comments.

Comments

0

I had a similar problem on a fresh WAMP installation. Turned out that HTTP file uploading was off in my php.ini file. So make sure it's on.

file_uploads = On

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.