Welcome Guest, Not a member yet? Register   Sign In
passing form data back to model before processing images.
#1

[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">
  &lt;?php if (isset($images) && count($images)):
   foreach($images as $image): ?&gt;
   <div class="span2">
    <a href="&lt;?php echo $image['url']; ?&gt;">
     <img src="&lt;?php echo $image['thumb_url']; ?&gt;" />
    </a>    
   </div>
  &lt;?php endforeach; else: ?&gt;
   <div id="blank_gallery">Please Upload an Image</div>
  &lt;?php endif; ?&gt;
</div>
</div>

<div class="span4">
<div id="upload">
  &lt;?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();
  ?&gt;
</div>
</div>
</div>

My Controller:
Code:
&lt;?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');
}
}
#2

[eluser]DarkManX[/eluser]
Code:
&lt;?=$this->input->post('size');?&gt;
#3

[eluser]l1v1[/eluser]
I think you simply just need to pass the
Code:
$this->input->post('size')
variable to
Code:
do_upload()
function.
Example:
Model:
Code:
function do_upload($size){
// your code
}
Controller:
Code:
if($this->input->post('upload')){
  
   $this->Gallery_model->do_upload($this->input->post('size'));
  }




Theme © iAndrew 2016 - Forum software by © MyBB