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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:11:30+00:00 2026-06-11T19:11:30+00:00

I am developing a form that allows the user to upload images as well

  • 0

I am developing a form that allows the user to upload images as well as data.
I have built forms before but am trying to integrate the file uploading class with my previous controller.

Below is the Controller, Model & Form from my View, can anyone help me tie up the missing link? I have searched all over & not found a solution

class Canvas extends CI_Controller {

function __construct() {
    parent::__construct();
                  $this->load->helper(array('form', 'url'));

}

function index() {
            $vars = array();
            $this->load->library('FacebookConnect');
            $facebook=$this->facebookconnect->connect();
            $vars['facebook'] = $facebook;
            $user = $vars['user'] = $facebook->getUser();
            $this->load->model('Users_Model'); 
            if($user != 0  && sizeof($_POST)>0) {
                // user already set up. Show thank you page
                $this->iterate_profile ($vars['user'],false,$_POST);
                $this->load->view('upload_form',$vars);
            } else {
                // user not set, show welcome message
                $this->load->view('canvas',$vars);
            }

}
    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

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

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

            $this->load->view('upload_form', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }
    }
    function thank_you() {
            $this->load->view('thank_you',$vars);
    }

    function remove() {
            $vars = array();
            $this->load->library('FacebookConnect');
            $facebook=$this->facebookconnect->connect();
            $vars['facebook'] = $facebook;
            $vars['user'] = $facebook->getUser();
            $this->load->model('Users_Model'); 
            if($vars['user'] == 0) {
                // user not set, redirect
                redirect('/', 'refresh');
            } else {
                // user already set up. Remove
                $this->load->model('Users_Model'); 
                $this->Users_Model->remove($vars['user']);
            }

            $this->load->view('removed',$vars);
    }

    protected function iterate_profile ($user,$breadcrumb,$item) {

        foreach($item as $key => $value) {
            if(is_array($value)) {
                $this->iterate_profile($user,$key,$value);
            }
            else {
                if($breadcrumb) {
                    //echo '[' . $breadcrumb . '_' . $key . ']= ' . $value . ' <br />';
                    $key = $breadcrumb . '_' . $key;
                }

                if( ! $this->Users_Model->exists($user,$key)) {
                    // does not exist in the database, insert it
                    $this->Users_Model->add($user,$key,$value);
                } else {
                    $this->Users_Model->update($user,$key,$value);
                }
            }
        }
    } 

Model:

class Users_Model extends CI_Model {
protected $_name = 'users';

function add($id,$key,$value) {
    $data = array(
       'id' => $id,
       'name' => $key,
       'value' => $value
    );

    return $this->db->insert($this->_name, $data); 
}
function update($id,$key,$value) {
    $data = array(
       'value' => $value
    );

    $this->db->where(array(
       'id' => $id,
       'name' => $key
    ));
    return $this->db->update($this->_name, $data); 
}

function exists($id,$key=null) {
    if($key == null) {
        $this->db->where(array(
        'id' => $id
        ));
    } else {
        $this->db->where(array(
        'id' => $id,
        'name' => $key
        ));  
    }

    $query = $this->db->get($this->_name);
    if($query->num_rows() > 0) {
        return true;
    }
    return false;
}

function remove($id) {
    $data = array(
       'id' => $id,
    );

    return $this->db->delete($this->_name, $data); 
}

function all() {
    $query = $this->db->get($this->_name);
    $results = array();
    if($query->num_rows() > 0) {
        foreach($query->result() as $row) {
            $results[]=$row;
        }
    } 
    return $results;  
}

}

Form in view:

        <form action="./" method="post" accept-charset="utf-8" enctype="multipart/form-data">
              <table>
                    <tr><td><b class="ara">XXXXXXXX</b> <input id="name" type="text" name="uid" value="" size="30"></td></tr>
                    <tr><td><b class="ara">XXXXXXXX</b><input id="dob" type="text" name="date_of_birth" value="" size="30"></td></tr>
                    <tr><td><b class="ara" >XXXXXXXX</b><input id="email" type="text" name="email" value="" size=30></td></tr>
                    <tr><td><b class="ara">XXXXXXXX</b> <input id="tel" type="text" name="telephone" value="" size="30"></td></tr>
                    <tr><td><input type="radio" name="device" value="11" checked><b>XXXXXXXX</b></input>
                                  <input type="radio" name="device" value="305"><b>XXXXXXXX</b></input>
                                  <input type="radio" name="device" value="306"><b>XXXXXXXX</b></input></td></tr>
                    <tr><td><b>XXXXXXXX</b><select name="reason"> 
                    <option value="volvo">XXXXXXXX</option> 
                    <option value="saab">XXXXXXXX</option> 
                    <option value="mercedes">XXXXXXXX</option> 
                    <option value="audi">XXXXXXXX</option></select></td></tr>
                    <tr><td><b>XXXXXXXX</b><select name="game">
                    <option value="chuzzle">XXXXXXXX</option> 
                    <option value="tetris">XXXXXXXX</option> 
                    <option value="speed">XXXXXXXX</option></select></td></tr>
                    <tr><td><input type="file" name="userfile" class="upload" size="30"/></td></tr>
                    <tr><td><span class="ara tandc">XXXXXXXX</span></td><td><input id="checkme" type="checkbox" class="check" name="Check me" value="Submit"/></td></tr>
                    <tr><td><b><input type="button" class="btn" id="send" name="Add me" value="Submit"/></td></tr>
              </table>
        </form>
  • 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-11T19:11:31+00:00Added an answer on June 11, 2026 at 7:11 pm

    What error are you actually getting? One problem I see at first glance is that the form submits to ./, not do_upload, so that code probably never runs?

    From index(), run do_upload() and change it so it returns true/false depending on success. If there was an error, save it to a class variable like this:

    class Canvas extends CI_Controller {
    
        private $upload_error = '';
    
        function __construct() {
        ...
    

    Then in do_upload(), instead of doing:

    $error = array('error' => $this->upload->display_errors());
    

    You can do:

    $this->upload_error = array('error' => $this->upload->display_errors());
    

    And in index(), if the result of calling do_upload() is false, read the error from $this->upload_error

    Overall, your do_upload() method would look like this:

        function do_upload()
        {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
    
            $this->load->library('upload', $config);
    
            if ( ! $this->upload->do_upload())
            {
                $this->upload_error = array('error' => $this->upload->display_errors());
    
                return false;
            }
            else
            {
                //$data = array('upload_data' => $this->upload->data());
                return true;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing RESTAURANT web site. I have a form that allows restaurant owners
I am developing a form that allows users to enter their credit card information
I´m developing a simple form that allows users to check availability in a hotel
I am developing a web application that allows a user to add entries to
Currently I am developing a windows form application in c# that has several forms.
Im currently developing an webapplication that are going to have an Autocomplete search form,
In an application I'm developing, I have a main form that simply sits there
I'm developing a basic web form that allows users to search certain columns in
I am developing UI form that has infragistics grid. Users can delete, submit some
i am developing register form using php where i need to upload the file

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.