LiveEn
LiveEn

Reputation: 3253

Skip "You did not select a file to upload" error and display all other errors

When I upload images, how do I ignore the "You did not select a file to upload" error and display all the other errors when an image is being upload?

for($i = 1; $i < 6; $i++) {
    $upload = $this->upload->do_upload('image'.$i);

    if (!$upload) {
        $error = array('error' => $this->upload->display_errors());
        var_dump($error);
    } else {
        $images = $this->upload->data();
    }
}

What I want to do is when $upload fails because no files have been uploaded, run:

$images = $this->upload->data();

Or display the other image upload error. How can I do it?

Upvotes: 0

Views: 1510

Answers (1)

stormdrain
stormdrain

Reputation: 7895

You can't -- there are no other errors nor data. If you look at the Upload library, you will see that the very first thing (understandably) it checks for is to see if there is a file. If there is no file, it sets the error and exits so nothing else gets processed:

// Is $_FILES[$field] set? If not, no reason to continue.
if ( ! isset($_FILES[$field]))
{
    $this->set_error('upload_no_file_selected');
    return FALSE;
}

Upvotes: 2

Related Questions