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

[eluser]swgj19[/eluser]
I am almost through building a simple gallery, but need help on the logic.
The gallery is using code from the CI file upload series.

I basically have a form that displays title, description, and image field to upload an image. I have already set up where the image uploads to a directory and makes a thumb on the server. That was not to difficult.

Now I am trying to upload a title and description with an image id stored in the db.
The image id will have to be joined with the title and description id.

I will also add validation to prevent sql injection.

So, what are the steps(logic) to assign id to an image. Store the images. Relate the title and description id to the image id. So when the gallery is viewed, the title and description will be next to the correct corresponding image.

Here is the page where the title and description will be next the image
http://www.cradlewebdesign.com/index.php/gallery/index

Thanks.


Controller
Code:
<?php
class Gallery extends CI_Controller {

function index() {
  
  $this->load->model('Gallery_model');
  
  
  
  if ($this->input->post('upload')) {
   $this->Gallery_model->do_upload();
  }
  
  $data['images'] = $this->Gallery_model->get_images();
  $data['title'] = $this->input->post('title');
  $data['title'] = $this->input->post('description');  
  
  
  $data['left_content'] = 'gallery_left';
  $data['right_content'] = 'gallery_right';
  $this->load->view('includes/template', $data);
}

}

Model
Code:
<?php
class Gallery_model extends CI_Model {

var $gallery_path;
var $gallery_path_url;

function Gallery_model() {
  parent::__construct();
  
  $this->gallery_path = realpath(APPPATH . '../images');
  $this->gallery_path_url = base_url().'images/';
}

function do_upload() {
  
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path' => $this->gallery_path,
   'max_size' => 2000
  );
  
  $this->load->library('upload', $config);
  $this->upload->do_upload();
  $image_data = $this->upload->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();
  
}

function get_images() {
  
  $files = scandir($this->gallery_path);
  $files = array_diff($files, array('.', '..', 'thumbs'));
  
  $images = array();
  
  foreach ($files as $file) {
   $images []= array (
    'url' => $this->gallery_path_url . $file,
    'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
   );
  }
  
  return $images;
}

}

View

Code:
<div id="upload">
  &lt;?php
  echo form_open_multipart('gallery');
  //userfile is from file upload library
  echo form_input("title", "title");
  ?&gt;
        <br />
        &lt;?php
  echo form_textarea("description", "website description", "200", "200");
  ?&gt;
        <br />
        &lt;?php
  echo form_upload('userfile');
  echo form_submit('upload', 'Upload');
  echo form_close();
  ?&gt;  
</div>


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