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 8932215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:17:20+00:00 2026-06-15T09:17:20+00:00

I have two fields to upload two extensions: first field to upload (PDF,doc,docx) second

  • 0

I have two fields to upload two extensions:

  • first field to upload (PDF,doc,docx)

  • second field to just upload (zip)

How can I make Codeigniter validate different extensions for different fields?

/**
 * change book source file
 * 
 * @param integer $book_id 
 */
public function upload_book_source($book_id) {
    $vars = array();
    $vars['upload_path'] = PUBPATH . 'global/modules/bookstore/files/books_source_file/';
    $vars['allowed_types'] = 'doc|docx|pdf|zip';
    $vars['max_size'] = '30720';
    $vars['encrypt_name'] = TRUE;
    $vars['book_id'] = $book_id;

    $book = $this->d_book->find_by_id($book_id);
    if (isset($_POST['submit'])) {
        $file_name = $this->upload($vars);
        $this->d_book->update_one_field($book_id, 'bo_path', $file_name[0]['file_name']);
        $this->d_book->update_one_field($book_id, 'bo_path_zip', $file_name[1]['file_name']);

        $this->session->set_flashdata('success_msg', lang('file_uploaded'));
        redirect('bookstore/admin_d_book/');
    } else {
        $vars['upload_errors'] = NULL;
    }

    if ($book->bo_path) { // load cover image
        $vars['file_path'] = base_url() . 'global/modules/bookstore/files/books_source_file/' . $book->bo_path;
    } else {
        $vars['file_path'] = NULL;
    }
    $vars['controller_name'] = 'admin_d_book';
    $this->view('bookstore/admin/change_source_file', $vars);
}

/**
 * 
 * @param array $config the configuration array
 * @return string
 * 
 */
private function upload($config) {
    $this->load->library('upload', $config);
    for ($i = 1; $i <= 2; $i++) {

        if (!empty($_FILES['file' . $i]['name'])) {

            if (!$this->upload->do_upload('file' . $i))
                $vars['upload_errors'] = $this->upload->display_errors("<p class='notification n-error'>", "</p>");
            else
                $result[] = $this->upload->data();
        }
    }
    return $result;
}
  • 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-15T09:17:20+00:00Added an answer on June 15, 2026 at 9:17 am

    You need different configurations so you can change the allowed_types for the different inputs, example:

    echo form_open_multipart();
    echo form_upload('mydoc'); // <input type="file" name="mydoc">
    echo form_upload('myzip'); // <input type="file" name="myzip">
    echo form_close();
    
    $config = array(
        // your default config
    );
    $this->load->library('upload', $config);
    
    $config['allowed_types'] = 'doc|docx|pdf';
    $this->upload->initialize($config);
    $this->upload->do_upload('mydoc');
    
    $config['allowed_types'] = 'zip';
    $this->upload->initialize($config);
    $this->upload->do_upload('myzip');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to rails validation. I have two fields: field :feed_entitlements, :type =>
I have an upload form with two file upload fields. I am trying to
I have a form that contains two fields to upload files. I need to
I have two fields on the form ( forgotpassword form ) username and email
I have two fields in separate linked tables with the same data, but different
I have two fields on my web page ie: BookAuthor and BookDescription.On submit,the page
I have two fields - amount (decimal (11, 2)) - gift_amount (decimal (11, 2))
I have two fields that need to multiply each other and fill a third
I have two fields which calculate a total, but I have a radio button
I have two fields that I'd like to match. (already done the validation functions

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.