[eluser]Unknown[/eluser]
Hello,
I'm working on a new project that requires a simple admin for photo uploads.
One of the requirements of the upload tool is the need to choose from a dropdown menu
a few size for the thumbnail to be generated.
I have the upload tool working as intended but need some guidance on passing the users dropdown choice
to the model before processing the image thumb.
Here is my model :
Code:
<?php
class Gallery_model extends CI_Model{
var $gallery_path;
var $gallery_path_url;
function __construct(){
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../images/people');
$this->gallery_path_url = base_url().'images/people/';
}
function do_upload(){
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path
);
$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_ratio' => TRUE,
'width' => 100,
'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', 'originals'));
$images = array();
foreach ($files as $file){
$images []= array(
'url' => $this->gallery_path_url . $file,
'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
);
}
return $images;
}
}
$this->load->library('image_lib', $config);
My View:
Code:
<div class="container">
<div class="span12">
<div id="gallery">
<?php if (isset($images) && count($images)):
foreach($images as $image): ?>
<div class="span2">
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['thumb_url']; ?>" />
</a>
</div>
<?php endforeach; else: ?>
<div id="blank_gallery">Please Upload an Image</div>
<?php endif; ?>
</div>
</div>
<div class="span4">
<div id="upload">
<?php
$frm=array('class'=>'form-inline');
$attr=array('name'=>'upload','class'=>'btn btn-primary');
$attr1=array('name'=>'userfile','class'=>'input-file');
$options=array('200'=>'large','100'=>'small');
echo form_open_multipart('gallery',$frm);
echo form_upload($attr1);
echo form_dropdown('size',$options, 'small');
echo form_submit($attr,'upload');
echo form_close();
?>
</div>
</div>
</div>
My Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Gallery extends CI_Controller {
public function index(){
$this->load->model('Gallery_model');
if($this->input->post('upload')){
$this->Gallery_model->do_upload();
}
$data['images'] = $this->Gallery_model->get_images();
$this->load->view('header');
$this->load->view('gallery', $data);
$this->load->view('footer');
}
}