[eluser]johanriyan[/eluser]
i want share upload image to database.
this is view v_upload.php
Code:
<div class="container">
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</div>
this is view success upload name is v_upload_success.php
Code:
<div class="container">
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</div>
my controller
Code:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('m_admin');
}
function index()
{
$this->load->view('v_upload', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('v_upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->m_admin->upload($this->upload->data());
$this->load->view('v_success_upload', $data);
}
}
}
?>
and model like this :
Code:
public function upload($image_data = array())
{
$data = array(
'image' => $image_data['file_name']
);
return $query=$this->db->insert('upload', $data);
}
before try, you must create table name upload
and filed image.