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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:10:08+00:00 2026-05-19T02:10:08+00:00

this is going to be hazy… i have built a crud system for managing

  • 0

this is going to be hazy… i have built a crud system for managing “offers” in a db with an upload field on both the create form and the update form.

when the user goes to edit i have the image displayed but if they want to upload a new one the form field is there in the update form to upload a new image when they submit the updates

the tricky part is if they don’t want to $this->upload->do_upload() will dump out an error saying no image specified

To combat this I added on if(!empty($_POST[‘userfile’])) to only use the upload class if an image was specified, but when the form submits this seems to be empty always until it gets to the upload class function call.. heres some code

$userfile = $this->input->post('userfile');//i have tried $_POST as well


if( ! empty($userfile))
            {
                if ( ! $this->upload->do_upload())
                {
                    $error = array('error' => $this->upload->display_errors());
                    echo $this->upload->display_errors();

                    $data['offer'] = $this->moffers->get_offer($this->input->post('id'));
                    $this->load->view('admin/admin_header');
                    $this->load->view('admin/edit',$data);
                    $this->load->view('admin/admin_footer');
                }   

any ideas on a solution of what is going wrong? the upload field works fine when i take out the empty() condition but wont work if the user doesnt specify a file to upload which they may not always want to do

<tr>
        <td>Upload a new image</td>
        <td><input type="file" name="userfile" size="40" /></td>
    </tr>
  • 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-05-19T02:10:08+00:00Added an answer on May 19, 2026 at 2:10 am

    Do it like this:

        if(isset($_FILES['userfile']['tmp_name']) && !empty($_FILES['userfile']['tmp_name'])):
            if ( ! $this->upload->do_upload())
                {
                    $error = array('error' => $this->upload->display_errors());
                    echo $this->upload->display_errors();
    
                    $data['offer'] = $this->moffers->get_offer($this->input->post('id'));
                    $this->load->view('admin/admin_header');
                    $this->load->view('admin/edit',$data);
                    $this->load->view('admin/admin_footer');
                }
        endif;
    

    That’s how I did it in one of my codeigniter projects.

    I also created a codeigniter upload helper, can always be usefull 😉 -> http://blog.cmstutorials.org/freebees/codeigniter-free-upload-helper

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

Sidebar

Related Questions

Is this going to be a problem? I have a legacy system which uses
This is going to be a stupid question but I have spent an inordinate
I nearly have this going but don't have sufficient brain power to work out
have a php code like this,going to convert it in to C#. function isValid($n){
Okay. Complex Title for a simple(?) problem. I have something like this going on
Okay. Complex Title for a simple(?) problem. I have something like this going on
I'm working with pointer-to-member types inside templates, currently I have something like this going
I have something like this going on in my Java program: void f(Object o)
I am having some road blocks getting this going. I have 4 navigation links
I'm trying to use AJAX (not jQuery).... I basically have this going on. Content

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.