BUAT FORM UPLOAD
Dengan Text
Editor, Buatlah sebuah Form dengan Nama upload_form.php.
Kemudian salin script dibawah dan simpan di folder applications/views/upload/ :
<html>
<head><title>Upload
Form</title></head>
<body><?php
echo $error;?>
<?php
echo form_open_multipart('ci/do_upload');?>
<input
type="file" name="userfile" size="20" /><br
/><br />
<input
type="submit" value="upload" /></form>
</body></html>
Dengan Text
Editor, Buatlah sebuah Form dengan Nama upload_success.php. Kemudian
salin script dibawah dan simpan di folder applications/views/upload/
:
<html>
<head><title>Upload
Form</title></head>
<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('ci/upload', 'Upload Another File!'); ?></p>
</body></html>
DI FOLDER CONTROLLER
Dengan Text
Editor, Buatlah sebuah Form dengan Nama ci.php. Kemudian salin script
dibawah dan simpan di folder applications/controllers/
:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class
Ci extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->helper(array('form',
'url'));}
public function index(){//dikosongkan
dulu}
public function show(){
$data['n'] = $this->ModelNews->getAllNews();
$this->load->view('ci/isi2', $data);}
public function upload(){
$this->load->view('upload/upload_form',
array('error' => ' ' ));}
public function do_upload(){
$config['upload_path']
= './application/views/upload/uploads';
//$config['allowed_types']
= 'gif|jpg|png';
$config['allowed_types']
= '*';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload',
$config);
$this->upload->initialize($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/upload_success',
$data);}}}
Penampakan
:
Gambar
: upload_form.php
Gambar
:upload_success.php
Gambar
: ci.php di folder controller
Gambar
: Setting Upload.php di Folder System/Libraries/ untuk bisa upload semua file
Gambar
: Struktur Folder Upload
Gambar
: Tampilan Form Upload
Gambar : Tampilan Sukses Upload Gambar Logo Seamolec
Gambar
:Tampilan Sukses Upload Gambar Logo ITB
Gambar
: Folder Tempat Uploadsnya
Referensi
: User Guide Form Upload CI
nice post, thanks for sharing. zte v956
ReplyDelete