Welcome Guest, Not a member yet? Register   Sign In
Upload image to database

I'm really new to CI,
and I try to build a page where I can upload information of product with its image.

Here is my view :

<title>Soft Eng</title>
<?php echo form_open_multipart('welcome/masuk'); ?>
<td>&lt;?php echo form_label('Product Name', $prod_name); ?&gt;</td>
<td>&lt;input type="text" name="prod_name" value="&lt;?php echo set_value('prod_name'); &gt;"size="50" /&gt;&lt;/td>
<td>&lt;?php echo form_label('Price', $price); ?&gt;</td>
<td>&lt;input type="text" name="price" value="&lt;?php echo set_value('price'); ?&gt;" size="11" /&gt;&lt;/td>
<td>File :</td>
<td>&lt;input type="file" name="image" value="&lt;?php echo set_value('image'); ?&gt;"&gt;&lt;/td>
&lt;?php echo form_submit('contact', 'Post'); ?&gt;
&lt;?php echo form_close(); ?&gt;

and here is the function in my controller :

function masuk ()

$info['Created'] = date('Y-m-d H:i:s');
$info['prod_name'] = $this->input->post('prod_name', true);
$info['price'] = $this->input->post('price');
$info['username'] = $this->tank_auth->get_username();  
$info['category'] = $this->input->post('catchoice');
$file = $_FILES['image']['tmp_name'];
$info['gambar'] = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);

if ($this->db->insert($this->table_name, $info))
     $this->load->view('contact', $info);

I have problem with the image upload,
I check about the file upload in CI user guide,
but I don't understand how to use it since I have other things to do in the same function (insert data for product information)

Thanks before,

Theme © iAndrew 2016 - Forum software by © MyBB