Welcome Guest, Not a member yet? Register   Sign In
file uploading with text and description
#11

[eluser]swgj19[/eluser]
I organized the code, but cannot get it to work at all now.
It is not displaying the photos on the server or storing the photo path in the db.

These are the errors I am getting:

Undefined variable: data

Filename: controllers/gallery.php

Line Number: 64

&

Undefined variable: image_data

Filename: models/gallery_model.php

Line Number: 12

Code:
<?php
class Gallery_model extends CI_Model {



function store_image_db($data) {
  
  $data = array(
       'id' => $this->input->post('id'),
       'title' => $this->input->post('title'),
       'description' => $this->input->post('description'),
       'path' => $image_data['full_path'],
       'thumb_path'=> $image_data['file_path'] . 'thumbs/'. $image_data['file_name']
  
);
  
   $this->db->insert('photos', $data);
}



}

Code:
<?php
class Gallery extends CI_Controller {

  var $gallery_path;
  var $gallery_path_url;

function index() {
  
  
  $this->load->model('Gallery_model');
  
  $this->gallery_path = realpath(APPPATH . '../images');
  $this->gallery_path_url = base_url().'images/';
  
  //Step 2: // Is the form being submitted?
  if ($this->input->post('upload')) {
  
  //Step 3: image configuration
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path' => $this->gallery_path,
   'max_size' => 2000,
   'encrypt_name'  => true
  );
  
  $this->load->library('upload', $config);
  
   //Step 4: Set the validation rules.
            $this->form_validation->set_rules(array(
                array(
                    'field' => 'title',
                    'label' => 'Title',
                    'rules' => 'required',
                ),
                array(
                    'field' => 'description',
                    'label' => 'Description',
                    'rules' => 'required',
                ),
            ));

            // Step 5: Run validation
            if ($this->form_validation->run())
            {
  
  
  
  $this->upload->do_upload();
  //Step 6: Capture image upload data
  $image_data = $this->upload->data();
  
  //Step: 7 Resize captured image data
  $config = array(
   'source_image' => $image_data['full_path'],
   'new_image' => $this->gallery_path . '/thumbs',
   'maintain_ration' => true,
   'width' => 150,
   'height' => 100
  );
  
  $this->load->library('image_lib', $config);
  $this->image_lib->resize();
  
  $this->Gallery_model->store_image_db($data);
  
  //Step 8: Set image paths files var to data array
  $data['images'] = array(
  
   $files = scandir($this->gallery_path),
   $files = array_diff($files, array('.', '..', 'thumbs'))
  );
  
  $images = array();
  
  //Step 9: Loop image data set to var images
  foreach ($files as $file) {
   $images []= array (
    'url' => $this->gallery_path_url . $file,
    'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
   );
  }
  
  return $images;

  
   $data['left_content'] = 'gallery_left';
   $data['right_content'] = 'gallery_right';
   $this->load->view('includes/template', $data);
  
}
  
  
  
  
  
  }
}

}


Messages In This Thread
file uploading with text and description - by El Forum - 11-09-2012, 10:40 PM
file uploading with text and description - by El Forum - 11-09-2012, 11:09 PM
file uploading with text and description - by El Forum - 11-10-2012, 06:42 AM
file uploading with text and description - by El Forum - 11-10-2012, 11:18 PM
file uploading with text and description - by El Forum - 11-11-2012, 03:42 AM
file uploading with text and description - by El Forum - 11-11-2012, 11:49 AM
file uploading with text and description - by El Forum - 11-11-2012, 02:31 PM
file uploading with text and description - by El Forum - 11-11-2012, 09:07 PM
file uploading with text and description - by El Forum - 11-11-2012, 09:20 PM
file uploading with text and description - by El Forum - 11-12-2012, 01:51 AM
file uploading with text and description - by El Forum - 11-12-2012, 05:43 AM
file uploading with text and description - by El Forum - 11-12-2012, 05:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB