Welcome Guest, Not a member yet? Register   Sign In
upload not working
#1

[eluser]junaids[/eluser]
Hi,
I am trying to develop a product adding controller. I am trying to insert product data in the database and the product image to be uploaded to the images directory. The data is inserted correctly into the db but the image is not uploaded in the directory. below is my code
VIEW
Code:
<!DOCTYPE HTML>
&lt;html lang="en-US"&gt;
&lt;head&gt;
&lt;title&gt;CI Gallery&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
   <div id="blank_gallery">Please Add Product Description</div>

<div id="product_name">
&lt;?php echo form_open('gallery/index'); ?&gt;
    &lt;?php
echo form_input('product_name');
echo form_label('Product Name');
echo form_error('product_name');
?&gt;
    <div id="product_price">
    &lt;?php
echo form_input('product_price');
echo form_label('Product Price');
echo form_error('product_price');
?&gt;
    </div>

<div id="gallery">
   <div id="blank_gallery">Please Upload a Product Image</div>
</div>

<div id="upload">
  &lt;?php
  echo form_open_multipart('gallery');
  echo form_upload('userfile');
  echo form_submit('upload', 'Add Product');
  echo form_close();
  ?&gt;  
</div>
&lt;/body&gt;
&lt;/html&gt;

Here is my Controller
Code:
&lt;?php
class Gallery extends Controller {

function index() {
  $this->load->model('Gallery_model');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('product_name', 'Product Name', 'required');
  $this->form_validation->set_rules('product_price', 'Product Price', 'required|numeric');
  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('gallery');
  }
  else
  {
  $this->Gallery_model->add_product();
  $this->Gallery_model->do_upload();
  $this->load->view('product_added');
  }
  }
}

and MODEL
Code:
&lt;?php
class Gallery_model extends Model {

var $gallery_path;
var $gallery_path_url;

function Gallery_model() {
  parent::Model();
  
  $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 add_product()
          {
         $this->load->database();
  $data = array(
                'name'   => $_POST['product_name'],
  'price'   => $_POST['product_price'],
  );  
                $this->db->insert('products', $data);
          }
}

Need help..Why are the images not uploaded in the directory?


Messages In This Thread
upload not working - by El Forum - 02-09-2012, 02:12 AM
upload not working - by El Forum - 02-09-2012, 02:14 AM
upload not working - by El Forum - 02-09-2012, 02:19 AM
upload not working - by El Forum - 02-09-2012, 02:40 AM
upload not working - by El Forum - 02-09-2012, 02:43 AM
upload not working - by El Forum - 02-09-2012, 03:00 AM
upload not working - by El Forum - 02-09-2012, 05:16 AM
upload not working - by El Forum - 02-09-2012, 08:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB