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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:56:22+00:00 2026-06-13T02:56:22+00:00

Im using a custom form validator function to check if an image type file

  • 0

Im using a custom form validator function to check if an image type file is being uploaded. Its quite simple, but no matter what I try I cant seem to get the validator to pass the variable correctly.

HTML

<input type="file" name="image" /><div><?php echo form_error('image'); ?></div>

CONTROLLER

public function postAd(){
    $this->form_validation->set_rules("image", "image", "callback_valid_image");

     if ($this->form_validation->run()==FALSE){
            $this->load->view('header', array('title'=>"Post an ad"));
            $this->load->view('ads/default');
            $this->load->view('footer');
        }else{
            echo "EMPTY";
        }
}

public function valid_image($file){
     echo "RAW:" . $file . "<br />";
     echo "FILE:",$_FILES[$file];
}

I have set up the messages in the form_validation language file too.

Regardless of what type of file I enter, or if I leave it blank, it will never show any file at echo “RAW” or echo “FILE” lines.

  • 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-13T02:56:23+00:00Added an answer on June 13, 2026 at 2:56 am

    The Form Validation Library does not apply to the $_FILES array, only to $_POST. You should use the File Uploading Library and use something like:

    if (!$this->upload->do_upload()){
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('upload_form', $error);
    }
    else{
        //upload worked.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this jQuery form validator but I cannot understand how to make one
I'm using this function, to submit form in the background, with custom messages. It
I am using jquery validation plugin for form validation. I have added a custom
I'm using a custom login form, the same as the one in wp-admin, the
I have a list within Sharepoint, using a custom new form I have added
My form has a custom element like below, created using custom ajax: <select jwcid=testtest
I am using Custom InfoPath Task Forms in my project. For form registering, I
Here is my code i am using for custom search, <div id=cse-search-form style=width: 100%;>Loading</div>
I'm using the following logic to add a custom handler to a form that's
I am trying to create a custom authentication scheme in ASP.NET MVC using form

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.