index.php
<html>
<head>
<title>upload</title>
</head>
<body>
<center><h1>Membuat Upload File </h1></center>
<?php echo $error;?>
<?php echo form_open_multipart('upload/aksi_upload');?>
<input type="file" name="berkas" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
sukses.php
<html>
<head>
<title>upload<</title>
</head>
<body>
<center><h1>Upload File Dengan CodeIgniter</h1></center>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
controller :
<?php
class Upload extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index(){
$this->load->view('index', array('error' => ' ' ));
}
public function aksi_upload(){
$config['upload_path'] = './gambar/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$config['max_width'] = 10240;
$config['max_height'] = 7680;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('berkas')){
$error = array('error' => $this->upload->display_errors());
$this->load->view('v_upload', $error);
}else{
$data = array('upload_data' => $this->upload->data());
echo "<pre>";
print_r($data['upload_data']['file_name']);
echo "</pre>";
exit();
$this->load->view('sukses', $data);
}
}
}
Tidak ada komentar:
Posting Komentar