TUGAS CODE IGNITER UPLOAD FILE

Kali ini kami disuruh mencoba membuat sebuah form upload file dengan memanfaatkan user guide yang sudah terintegrasi di Code Igniter....

Berikut hasil dari Tugas yang saya kerjakan

Tampilan awalnya seperti ini
Tampilan jika button upload di klik tanpa choose file
Ketika di klik tombol Choose File


Ketika di Upload.....


File yang diperlukan:
upload__form.php (di folder views)
upload_sukses.php (di folder views)
upload (di folder controller)

Upload.php

<?php

class Upload extends CI_Controller {

function __construct()
{
parent::__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|zip|doc|docs|xls|ppt|pdf|txt';
$config['max_size'] = '1000';


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

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors('<p>','<br/>Silahkan ulang...!!!', '</p>'));

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

$this->load->view('upload_sukses', $data);
}
}
}
?>


upload_form.php

<html>
<head>
<title>Upload Form</title>
</head>

<body bgcolor="#4bc402">

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

upload_sukses.php

<html>
<head>
<title>Upload Form</title>
</head>

<body bgcolor="#4bc402">

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


EmoticonEmoticon