Welcome Guest, Not a member yet? Register   Sign In
view image
#1

[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 />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;
&lt;?php echo anchor('upload/view', 'view'); ?&gt;
&lt;/body&gt;
&lt;/html&gt;

This is my upload_success view
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3>Your file was successfully uploaded!</h3>

<ul>
&lt;?php foreach ($upload_data as $item => $value):?&gt;
<li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>

&lt;?php endforeach; ?&gt;
</ul>

<p>&lt;?php echo anchor('upload', 'Upload Another File!'); ?&gt;</p>




&lt;/body&gt;
&lt;/html&gt;

This is my view
Code:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;


<h1>&lt;?php echo $heading ?&gt;</h1>

&lt;?php foreach($query->result() as $row): ?&gt;

<p>&lt;?php echo $row->content ?&gt;</p>

<img src="&lt;?php echo $row-&gt;image_path ?&gt;" />



&lt;?php endforeach; ?&gt;

&lt;body&gt;
&lt;/html&gt;


Messages In This Thread
view image - by El Forum - 08-22-2012, 04:35 AM
view image - by El Forum - 08-22-2012, 05:57 AM
view image - by El Forum - 08-22-2012, 06:14 AM
view image - by El Forum - 08-22-2012, 08:35 AM
view image - by El Forum - 08-22-2012, 09:19 AM
view image - by El Forum - 08-22-2012, 10:12 AM
view image - by El Forum - 08-22-2012, 10:17 AM
view image - by El Forum - 08-23-2012, 01:22 AM
view image - by El Forum - 08-23-2012, 01:42 AM
view image - by El Forum - 08-23-2012, 02:32 AM
view image - by El Forum - 08-23-2012, 03:00 AM
view image - by El Forum - 08-23-2012, 03:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB