• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Storing image filename to DB along with other data


I have a form with multiple inputs (text) and one file input(for images) what I would like to do is to store image filename to DB with other submitted data,
this is my controller http://pastebin.com/K6s34xRe and my
model http://pastebin.com/9ddj4uTX
(method "dodaj_sliko() is save_image() in english)

My field for files is
<input type="file" name="file_upload_manual_slike" multiple />

So the main question is, how can I accomplish this, because above code that I posted doesn't work :-S

[eluser]Oscar Dias[/eluser]
I think that your upload is not executed because it is right after a redirect:
redirect($this->config->item('base_url'), 'refresh');

The redirect function has an exit, which means it will stop execution after it.
function redirect($uri = '', $method = 'location', $http_response_code = 302)
  if ( ! preg_match('#^https?://#i', $uri))
   $uri = site_url($uri);

   case 'refresh' : header("Refresh:0;url=".$uri);
   default   : header("Location: ".$uri, TRUE, $http_response_code);

You need to do the upload before the redirect.

are you using codeigniters upload class if so you pass the variable to the model like this, here is mine using "do_upload":
function add_product($file_name) {
  $data = array(
  'product_name' =>$_POST['product_name'],
  'description' =>$_POST['product_description'],
  'price' => $_POST['product_price'],
  'discount_price' => $_POST['discount_price'],
  'thumbnail'=> $file_name,
  'image'=> $file_name
   $this->db->insert('product', $data);
And here is the portion of my controller
if (!empty($_FILES['product_thumb']))
            // Specify configuration for File 1
            $config['upload_path'] = './shop_images/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';      

            // Initialize config for File 1

            // Upload file 1, product_thumb is the name of my input for upload
            if ($this->upload->do_upload('product_thumb'))
                $data = array(
                    'thumbnail' => $this->upload->data()
     $file_name = $data['thumbnail']['file_name'];
                echo $this->upload->display_errors();
then pass it through to the model like so:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.