[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);
}
}
}
}