• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload image to database

#1
[eluser]Unknown[/eluser]
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 :

Code:
<html>
<head>
<title>Soft Eng</title>
</head>
<body>
<?php echo form_open_multipart('welcome/masuk'); ?>
  
<table>
  
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<td>File :</td>
<td>&lt;input type="file" name="image" value="&lt;?php echo set_value('image'); ?&gt;"&gt;&lt;/td>
</tr>
  
</table>
&lt;?php echo form_submit('contact', 'Post'); ?&gt;
&lt;?php echo form_close(); ?&gt;

and here is the function in my controller :

Code:
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,


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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