CI : Membuat Form Upload

August 3, 2012 § Leave a comment

Oke, Selanjutnya ayas akan coba berbagi tutor cara membuat form upload sederhana menggunakan CI, semoga bermanfaat🙂

Buat form dokumen baru dengan nama “upload_form.php” dan disimpan dalam folder C:\xampp\htdocs\D4B6\application\views

 

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


Buat form dokumen baru dengan nama “upload_success.php” dan disimpan dalam folder C:\xampp\htdocs\D4B6\application\views

script detail upload_success.php :

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

Buat form dokumen baru dengan nama “upload.php” dan disimpan dalam folder C:\xampp\htdocs\D4B6\application\controllers, dengan script sebagai berikut :

<?php
class Upload extends CI_Controller {
function __construct()
 {
 parent::__construct();
 $this->load->helper(array('form', 'url'));
 }
 function index()
 {
 $this->load->view('news/upload_form', array('error' => ' ' ));
 }
 function do_upload()
 {
 $config['upload_path'] = './uploads/';
 $config['allowed_types'] = 'gif|jpg|png';
 $config['max_size'] = '1000';
 $config['max_width'] = '1600';
 $config['max_height'] = '900';
 $this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array(‘error’ => $this->upload->display_errors());

$this->load->view(‘news/upload_form’, $error);
}
else
{
$data = array(‘upload_data’ => $this->upload->data());
$this->load->view(‘news/upload_success’, $data);
}
}
}
?>

Selanjutnya coba jalankan program, dan insyaAllah akan berhasil. Amin🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading CI : Membuat Form Upload at dimazfakhr.

meta

%d bloggers like this: