CodeIgniter Forums

Full Version: uploading images
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

so i created my upload
<title>Upload Form</title>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

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


and then the success
&lt;title&gt;Upload Form&lt;/title&gt;

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

&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;

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


class Upload extends CI_Controller {

function __construct()
  $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'] = '10000000000';
  $config['max_width']  = '10240000000000';
  $config['max_height']  = '76800000000000';

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
   $error = array('error' => $this->upload->display_errors());

   $this->load->view('upload_form', $error);
   $data = array('upload_data' => $this->upload->data());

   $this->load->view('upload_success', $data);
and i made the uploads folder in my root and it all works great. but i dont get how to create a view that will show the uploaded images in the folder and put the images on the page?