Skip to main content

Tanya Foto/Gambar agar bisa tampil setelah diupload

June 17, 2011 by jhono

jhono's picture

Hallo Master Master CI....!!mau tanya bagaimana nih cara menampilkan foto/gambar yang diupload...???untuk codingnya seperti ini,Jadi setelah file di upload di view hasil_upload langsung tampil foto/gambar yang kita upload..??
Tolong bantuannya ya..??
Controller: upload.php

class Upload extends controller{	
	function upload()
	{
		parent::controller();
	}	
	function index()
	{
		$this->load->view('form_upload', array('error' => ' ' ));
	}	
	function do_upload() 
	{
		$config['upload_path'] = './uploads/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']= '1100';
		$this->load->library('upload', $config);
		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());
			$this->load->view('form_upload', $error);
		}
		else 
		{
			$data = array('upload_data' => $this->upload->data());
			$this->load->view('hasil_upload', $data);
		}
	}	
}

View:
1. Form_upload

<html>
<head><title>Form Upload</title></head>
<body>
<?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>
</body>
</html>

2.Hasil_upload
<html>
<head>
<title>Form Upload</title>
</head>
<body>
<h3>File Berhasil Terupload</h3>
<p><?php echo anchor('upload', 'Upload FileLain'); ?></p>
</body>
</html>

Premium Drupal Themes by Adaptivethemes