Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:36:25+00:00 2026-06-07T11:36:25+00:00

I have a form with text inputs and a file input. What is a

  • 0

I have a form with text inputs and a file input. What is a proper way validate both input types using Codeigniter’s validation library? I found some solutions but they don’t work properly or seem like an overkill (creating new libraries or modifying CI system files).

In my view I’m using 1 multipart form and displaying both text validation error and upload errors.

Here is what I have so far in my Controller…

function create() //create new post
{           
    $this->form_validation->set_rules('content', 'Entry', 'trim|required|xss_clean');
    $this->form_validation->set_rules('category_id', 'Category', 'trim|required|xss_clean|integer'); 

    //Text input fields
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('new_post');
    }       
    else
    {
            $config['upload_path'] = './uploads/posts/';
            $config['allowed_types'] = 'jpg|png';               
            $config['max_size'] = '800'; //in KB

            $this->load->library('upload', $config);

            //File Upload
            if (! $this->upload->do_upload())
            {
                $upload_error['upload_error'] = array('error' => $this->upload->display_errors()); 

                $this->load->view('my_view', $upload_error);

                return FALSE;
            }

             //Add to database 
             $data = array (
               'user_id' => $this->tank_auth->get_user_id(),
               'category_id' => $this->input->post('category_id'),
               'content' => $this->input->post('content')
             );

             $this->Posts_model->create_post($data);

             $this->session->set_flashdata('success', 'Post_added!');
             redirect('posts');
    }       

}

I keep getting You did not select a file to upload. in my view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:36:26+00:00Added an answer on June 7, 2026 at 11:36 am

    What is the name of your file input? do_upload() is expecting it by default to be ‘userfile’, however if you have something like <input type="file" name="image"... you will need to call $this->upload->do_upload('image')

    You also need to make sure the form is set to multipart – http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form with some text inputs and a file input. I
I have a simple html form with two controls: input-text and input-file I need
I am trying to write data from form inputs to a text file using
I have form for example: <input type=text /> <input type=file /> <input type=submit />
I have a form with a few text inputs and also with one file-type
I have a form with 2 text inputs and 2 radio buttons, as below:
I have an ASP.NET form with three text inputs, one each for Work Phone,
i have two text inputs like the following, i don't want to use <form>
So i have a simple form that takes a few inputs (two text and
I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.