[eluser]shiva478[/eluser]
Hi
I'm new to php and codeigniter. I was doing a tutorial on file uploading class in
http://ellislab.com/codeigniter/user-gui...ading.html
I was able to insert the image path into my database. The only problem I have is that I want to view the images on the view and I'm not sure how I go about doing that.
This is my upload controller
Code:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('upload_model');
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$upload_info = $this->upload->data();
$insert_data = array(
'id' => $this->input->post('id'),
'image_path' => $upload_info['file_path'],
'content' => $this->input->post('content')
);
$this->db->insert('image', $insert_data);
$this->load->view('upload_success', $data);
}
}
function view(){
$data['title'] = "Voluptuous Decadents";
$data['heading'] = "Bras";
$data['query'] = $this->db->get('image');
//$this->load->view('layout');
$this->load->view('view', $data);
}
}
?>
This is my upload_model
Code:
<?php
class Upload_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_upload()
{
$query = $this->db->get('image');
}
}
?>
This is my upload_form
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<?php echo form_input('content', set_value('content', 'content'));?>
<br /><br />
<input type="submit" value="upload" />
</form>
<?php echo anchor('upload/view', 'view'); ?>
</body>
</html>
This is my upload_success view
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<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>
</body>
</html>
This is my view
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading ?></h1>
<?php foreach($query->result() as $row): ?>
<p><?php echo $row->content ?></p>
<img src="<?php echo $row->image_path ?>" />
<?php endforeach; ?>
<body>
</html>