0

I have the following set up in a Code Igniter application, however the file is not being passed through to the file uploader class. This is the second form on the page, just for reference and I have checked that they are both closed correctly.

The output I am getting is You did not select a file to upload. when I have been selecting an valid image.

View

<form action="../albums/upload" class="form-horizontal" method="post">
    <div class="form-group">
        <input type="file" name="userfile" required="" class="form-control">
    </div>
    <div class="form-group">
        <div class="col-md-4 col-md-offset-4">
            <input type="submit" id="upload" name="upload" class="btn btn-success" value="Upload">
        </div>
    </div>
</form>

Controller

public function upload() {
    if($this->input->post('userfile')){
        $this->model_photo->do_upload();
    }
}

Model

function do_upload() {
    $path = base_url().'res/image/';
    $config = array(
        'allowed_types' => 'jpg|jpeg|gif|png|tif|tiff',
        'upload_path' => $path
    );

    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload('userfile')) {
        $error = array('error' => $this->upload->display_errors());
        echo $error['error']; //echo debugging purposes
    } else {
        $data = array('upload_data' => $this->upload->data());
        echo $data['upload_data']; //echo debugging purposes
    }
}

1 Answer 1

1

in your <form> add enctype="multipart/form-data"

<form action="../albums/upload" class="form-horizontal" method="post" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

3 Comments

You're kidding... I looked at this and thought I had it in there but didn't actually check. I feel like an idiot now. Thank you!
I was once an victim of this too and wasted 2 hours noticing it .
Was just coming to accept today. I finished up last night before the 15 min went past.

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.