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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:22:21+00:00 2026-05-24T01:22:21+00:00

At this present point in time I have some code that does the following:

  • 0

At this present point in time I have some code that does the following:

I can edit and I can add a house sale that uploads/edits one image for this particular house and then during the process a thumbnail is created and then the original file name and the thumbnail name is saved to database fields called imagename and imagethumb.

(Note: Add and Edit a seprate pages)

What my idea is:

I will create another page that has the name of the houses fed into a dropdown menu so when one is selected and images are selected they will upload.

What my issue is:

  1. I am getting myself confused as to what would be the best way to modify my database to enable this change.

  2. How would I modify my php code to handle more then one file (How do I handle multiple images and then pass the image for uploading resizing etc ) What is the best option? – within my given idea?

  3. Could I have an example of what I should do so I can work off this.

I have included the model view and controller (As an Example) of my Add Sale but I will also need to edit a image for the respective sale.

Model:

class Sales_model extends CI_Model
{

    function __construct() {
            parent::__construct();
    }

    function getSalesPage($id = NULL) {

        $query = $this->db->get_where('sales', array('id' => $id), 1);
        if($query->num_rows() == 1) return $query->row();

    } # End getSalesPage

    function getSalesPages($id = NULL) { // $id does nothing
        $query = $this->db->get('sales');
        if($query->num_rows() > 0) return $query->result();

    } # End getSalesPages

    function getSalesContent($id = NULL) {
        $this->db->where('id', $id);
        $query = $this->db->get('sales', 1);

        if($query->num_rows() > 0) {
            $row = $query->result_array();
            return $row;
        }else{
            return FALSE;
        } # End IF
    } # End getSalesContent


    function addSale($data = NULL) {
        $this->db->insert('sales', $data);
        return TRUE;
    } # End Add Sale    

    function updateSale($id, $content) { //Content id from being passed

        $this->db->where('id', $id);  // selecting the $id to update
        $update = $this->db->get('sales'); // What does $update = well it = get the db sales
        $row = $update->row_array(); // what does $row mean = well it gets the row as an array

        if($update->num_rows() > 0) {

            if(isset($content['imagename']) && isset($content['thumbname'])) {

            #lets delete the image
            unlink("/includes/uploads/gallery/".$row['imagename']);
            #lets delete the thumb.
            unlink("/includes/uploads/gallery/thumbs/".$row['thumbname']);
        }
                $this->db->where('id', $id);
                if($this->db->update('sales', $content))
                {

                    return TRUE;
                }
                else
                {
                    return FALSE;
                }
            } # End IF
    } # End Update

    function deleteSale($id){

        $this->db->where('id', $id);
        $q = $this->db->get('sales');
        $row = $q->row_array();

        if ($q->num_rows() > 0){
            //delete from the database
            $this->db->where('id', $id); 
            $this->db->delete('sales');

            //lets delete the image
            unlink("includes/uploads/sales/".$row['imagename']);
            //lets delete the thumb.
            unlink("includes/uploads/sales/thumbs/".$row['thumbname']);
        }//END if num_rows
    }//END function deleteSale($id)
} # End Model

View:

    <?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$saleName = array('id' => 'name', 'name' => 'name','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('name'));
$saleLocation = array('id' => 'location', 'name' => 'location','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('location'));
$saleBedrooms = array('id' => 'bedrooms','name' => 'bedrooms','class' => 'validate[required[custom[number]]]', 'value' => set_value('bedrooms'));
$saleBathrooms = array('id' => 'bathrooms','name' => 'bathrooms','class' => 'validate[required[custom[number]]]', 'value' => set_value('bathrooms'));
$saleCondition = array('id' => 'condition','name' => 'condition','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('condition'));
$saleImage = array('id' => 'userfile', 'name'=> 'userfile');
$salePrice = array('id' => 'price','name' => 'price','class' => 'validate[required[custom[number]]]','value' => set_value('price'));
$saleDescription = array('id' => 'description','name' => 'description','class' => '', 'value' => set_value('description'));
$saleSubmit = array('id' => 'submit', 'name'=> 'submit', 'value' => 'Add Sale');
?>

<div id ="formLayout">
    <?php
    if($success == TRUE) {
    echo '<section id = "validation">Sale Added</section>'; 
    }
    echo '<section id = "validation">'.$message['imageError'].'</section>';
    ?>
<?php echo form_open_multipart('admin/addsale/', $formAddSale); ?>
<?php echo form_fieldset(); ?>

<?php echo form_label('Name:','name'); ?>
<?php echo form_input($saleName); ?>
<div id="errorName"><?php echo form_error('name'); ?></div>
<span class="small">Required Field - Text</span>

<?php echo form_label('Location:','location');?>
<?php echo form_input($saleLocation);?>
<div id="errorLocation"><?php echo form_error('location'); ?></div>
<span class="small">Required Field - Text</span>

<?php echo form_label('Bedrooms: ','bedrooms');?>
<?php echo form_input($saleBedrooms);?>
<div id="errorBedrooms"><?php echo form_error('bedrooms'); ?></div>
<span class="small">Required Field - Number</span>

<?php echo form_label('Bathrooms: ','bathrooms');?>
<?php echo form_input($saleBathrooms);?>
<div id="errorBathrooms"><?php echo form_error('bathrooms'); ?></div>
<span class="small">Required Field - Number</span>

<?php echo form_label('Condition: ','condition');?>
<?php echo form_input($saleCondition);?>
<div id="errorCondition"><?php echo form_error('condition'); ?></div>
<span class="small">Required Field - Text</span>

<?php echo form_label('Price: ','price');?>
<?php echo form_input($salePrice);?>
<div id="errorPrice"><?php echo form_error('price'); ?></div>
<span class="small">Required Field - Number</span>

<?php echo form_label('Image: ','userfile');?>
<?php echo form_upload($saleImage);?>
<div id="errorUserfile"><?php echo form_error('userfile'); ?></div>
<span class="small">Required Field - 1MB Max Size</span>

<?php echo form_label('Description: ','description');?>
<div id="errorDescription"><?php echo form_error('description'); ?></div>
<span class="small">Required Field - Text</span>
<?php echo form_textarea($saleDescription);?>
<script type="text/javascript">CKEDITOR.replace('description');</script>

<?php echo form_submit($saleSubmit);?>
<?php echo form_fieldset_close(); ?>
<?php echo form_close(); ?>
</div>

Controller:

class Addsale extends CI_Controller 
{ 
    function __construct()
    { 
        parent::__construct(); 
    } 

    function index() 
    { 
        if(!$this->session->userdata('logged_in'))redirect('admin/home');

            # Main Data

            $data['title'] = 'Add Sale: ';

            //Set Validation

            $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean'); 
            $this->form_validation->set_rules('location', 'Location', 'trim|required|xss_clean'); 
            $this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|numeric|required|xss_clean'); 
            $this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim|numeric|required|xss_clean'); 
            $this->form_validation->set_rules('condition', 'Condition', 'trim|required|xss_clean'); 
            $this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean'); 
            $this->form_validation->set_rules('price', 'Price', 'trim|required|xss_clean');

            if($this->form_validation->run()) {
            //Set File Settings 
            $config['upload_path'] = 'includes/uploads/sales/'; 
            $config['allowed_types'] = 'jpg|png'; 
            $config['remove_spaces'] = TRUE;
            $config['overwrite'] = TRUE;
            $config['max_size'] = '1024';
            $config['max_width'] = '1024'; 
            $config['max_height'] = '768'; 

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

            if(!$this->upload->do_upload()) {

                $data['message'] = array('imageError' => $this->upload->display_errors());
            } // Upload error end
            else{
                    $data = array('upload_data' => $this->upload->data());
                    $data['success'] = TRUE;
                    $config['image_library'] = 'GD2';
                    $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
                    $config['new_image'] = 'includes/uploads/sales/thumbs/';
                    $config['create_thumb'] = 'TRUE';
                    $config['thumb_marker'] ='_thumb';
                    $config['maintain_ratio'] = 'FALSE';
                    $config['width'] = '150';
                    $config['height'] = '150';

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


                $file_info = $this->upload->data(); 

                $this->db->escape($content);

                $content = array(   
                    'name' => $this->input->post('name', TRUE), 
                    'location' => $this->input->post('location', TRUE), 
                    'bedrooms' => $this->input->post('bedrooms', TRUE), 
                    'bathrooms' => $this->input->post('bathrooms', TRUE), 
                    'condition' => $this->input->post('condition', TRUE), 
                    'description' => $this->input->post('description', TRUE), 
                    'price' => $this->input->post('price', TRUE), 
                    'imagename' =>$file_info['file_name'],
                    'thumbname' =>$file_info['raw_name'].'_thumb'.$file_info['file_ext']
                );          

                $this->sales_model->addSale($content);
                }#end else
                } # End Form Validation       
                $data['content'] = $this->load->view('admin/addsale', $data, TRUE);
                $data['sales_pages'] = $this->sales_model->getSalesPages();
                $data['cms_pages'] = $this->navigation_model->getCMSPages();
                $this->load->view('admintemplate', $data);

            } # End Index Function 
        } # End Controller
  • 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-24T01:22:22+00:00Added an answer on May 24, 2026 at 1:22 am

    For handling dropdown, i think its easy one. But related multi upload stuff, you can use something like…

    in your view

    <?php echo form_label('Image: ','userfile1');?>
    <?php echo form_upload('userfile1');?>
    <?php echo form_label('Image: ','userfile2');?>
    <?php echo form_upload('userfile2');?>
    <!-- and so on -->
    <span class="small">Required Field - 1MB Max Size</span>
    

    Then in your controller, you can do this way

    //Set File Settings 
    $config['upload_path'] = 'includes/uploads/sales/'; 
    $config['allowed_types'] = 'jpg|png'; 
    $config['remove_spaces'] = TRUE;
    $config['overwrite'] = TRUE;
    $config['max_size'] = '1024';
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 
    
    $this->load->library('upload', $config);
    
    // Validate files for upload section...
    $success = array();
    $errors = array();
    $updload_files = array(
            'userfile1' => $_FILES['userfile1'],
            'userfile2' => $_FILES['userfile2'],
            // You can add more
            );
    
    foreach($updload_files as $field => $updload_file)
    {
        // Only process submitted file
        if($updload_file['error'] == 0)
        {
           // If there is an error, save it to error var
           if( ! $this->upload->do_upload($field) )
           {
               $errors[] = 'Failed to upload '.$field;  
           }
    
           // Use this to get the new file info if you need to insert it in a database
           $success[] = array( 'Success to upload '.$field => $this->upload->data());
        } 
        else 
        {
           $errors[] = $field . ' contain no data';  
        }
    }
    // Heres you could gettin know whats happen
    var_dump($errors);
    var_dump($success);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to code an app that at some point in time will have
I have some code in my application that looks something like this: char *hash
Say I have: void Render(void(*Call)()) { D3dDevice->BeginScene(); Call(); D3dDevice->EndScene(); D3dDevice->Present(0,0,0,0); } This is fine
I have an app that does an iteration to create points on a graph
I have this Access database that we use to run reports. The report is
I know that given enough time I'll figure this out, but it sure would
I just wrote some C code: #include <stdlib.h> #include <time.h> #include <string.h> typedef struct
I would like to have a regular expression that can work in a simple
So I've spent some time looking for an answer for this, but so far
I have a MonoTouch application that generates some PDFs locally and then prints them

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.