Home > web 3D ws > Upload Data file dengan Framework CI

Upload Data file dengan Framework CI

Selamat Pagi.. saya akan memposting tugas saya dari bapak jarwo. membuat file upload sebagai berikut :

File Upload_form.php

<head>

                <style type=”text/css”>

                                .head

                                {

                                                margin-left:18em;

                                                margin-top:4em;

                                                margin-right:18em;

                                                padding-left:18pt;

                                                padding-top:10pt;

                                                background:orange;

                                                height:4em;

                                                border-radius:25px 25px 0px 0px;

                                }

                                #body

                                {

                                                padding-left:18pt;

                                                padding-top:18pt;

                                                margin-left:18em;

                                                margin-right:18em;

                                                padding-left:18pt;

                                                background:skyblue;

                                                height:30em;

                                                border-radius:0px 0px 25px 25px;

                                }

                </style>

                </head>

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); //mengantisipasi jika ada yang mengakses file ini secara langsung

?>

<body>

                                <div class=”head”>

                                                <?php

                                                                echo “<h3>Upload File</h3>”;

                                                ?>

                                </div>

                                <div id=”body”>

                                                <?php echo $error;?>

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

                                                <form>

                                                                <input type=”file” name=”userfile” size=”20″ />

                                                                <br /><br />

                                                                <input type=”submit” value=”upload” />

                                                </form>

                                </div>

</body>

 

File Upload_success.java

 

<head>

                <style type=”text/css”>

                                .head

                                {

                                                margin-left:18em;

                                                margin-top:4em;

                                                margin-right:18em;

                                                padding-left:18pt;

                                                padding-top:10pt;

                                                background:orange;

                                                height:4em;

                                                border-radius:25px 25px 0px 0px;

                                }

                                #body

                                {

                                                padding-left:18pt;

                                                padding-top:18pt;

                                                margin-left:18em;

                                                margin-right:18em;

                                                padding-left:18pt;

                                                background:skyblue;

                                                height:30em;

                                                border-radius:0px 0px 25px 25px;

                                }

                </style>

                </head>

                <body>

                                <div class=”head”>

                                                <?php

                                                                echo “<h3>Upload File</h3>”;

                                                ?>

                                </div>

                                <div id=”body”>              

                                                <h3>File Anda berhasil diupload</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 file lain’); ?></p>

                                </div>

                </body>

 

File 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’;

                                $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());

                                                $this->load->view(‘upload_success’, $data);

                                }

                }

}

?>

Categories: web 3D ws
  1. No comments yet.
  1. No trackbacks yet.

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