Welcome Guest, Not a member yet? Register   Sign In
Unlink only if there is a new image to upload
#8

[eluser]jzmwebdevelopement[/eluser]
Hey Darren,

I have tried what you have said and it seems that if I have more then one sale and update the image it seems to change all data in the other sales to the one that I have chosen to update and not upload the image.

Why?

View:

Code:
<?php if($sales_pages): ?>
        <?php foreach($sales_pages as $sale): ?>
     <div id ="sales">
        <span class"thumbnail"><a >id?&gt;"><img class="thumbnailImg">thumbname?&gt;" alt=""/></a>
        <span class="location">&lt;?= $sale->location?&gt;</span>
        <span class="price">&lt;?= $sale->price?&gt;</span>
        </span>
                </div>

        &lt;?php endforeach; ?&gt;
&lt;?php endif; ?&gt;

Controller
Code:
class Editsale extends CI_Controller {
    /**
     * This document sets the following for the editsale page
     *PHP Validation
     *Thumbnail and Image Sizes
     *Image Locations
     *DB Settings
     * @author Jess McKenzie
     */

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

    }

    function index() {
       if(!$this->session->userdata('logged_in'))redirect('admin/home');
    
    $id = $this->uri->segment(4);
    # Set Main Page Data
        $data['title'] = 'Edit Sale:';
        $data['sales_pages'] = $this->sales_model->getSalesPages();
        $data['cms_pages'] = $this->navigation_model->getCMSPages();
        $data['sale']= $this->sales_model->getSalesContent($id);

         #Set The Validation Rules
                $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()) #If Valid Run
                {
                      $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)
                    );
                    
                    if($_FILES['userfile']['error'] != 4)
                    {  
                        //Set File Settings
                        //Set File Settings
                          $config['upload_path'] = 'includes/uploads/gallery/';
                          $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);
                        //Continue and resize the image
                        $data = array('upload_data' => $this->upload->data());
                        $config['image_library'] = 'GD2';
                        $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;             #resize
                        $config['new_image'] = 'includes/uploads/gallery/thumbs/';
                        $config['create_thumb'] = 'TRUE';
                        $config['thumb_marker'] ='_thumb';
                        $config['maintain_ratio'] = 'FALSE';
                        $config['width'] = '175';
                        $config['height'] = '175';

                        $this->load->library('image_lib', $config);
                        $this->image_lib->resize();    
                        
                
                        if(!$this->upload->do_upload()) //Process the upload function and uploads image
                        {
                            $data['message'] = array('imageError' => $this->upload->display_errors()); // Capture any $config errors and output them
                        }
                        else
                        {
                            $file_info = $this->upload->data(); //Returns an data array    
                            
                            // Append image data to content array in preparation for db update
                            $content['imagename'] = $file_info['file_name'];
                            $content['thumbname'] = $file_info['raw_name'].'_thumb'.$file_info['file_ext'];
                        }    
                    }    
              
                    // After everything, update DB
                    
                    if($this->sales_model->updateSale($id, $content))
                    {
                        $data['success'] = TRUE;
                    }
                    else
                    {
                        $data['success'] = FALSE;
                    }
                  
             } # End Form Validation


Messages In This Thread
Unlink only if there is a new image to upload - by El Forum - 05-06-2011, 11:12 PM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:12 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:15 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:35 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:20 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:36 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:38 AM
Unlink only if there is a new image to upload - by El Forum - 05-08-2011, 06:35 PM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 12:49 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 12:57 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 01:41 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 01:58 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:07 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:18 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:22 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:27 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:35 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:50 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:55 AM
Unlink only if there is a new image to upload - by El Forum - 05-10-2011, 02:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB