<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->library('upload');
$this->load->helper(['url','form']);
}
public function index(){
$res = ['res'=>$this->db->get('tb_file')->result()];
$this->load->view('upload_file',$res);
}
function store(){
$config['upload_path'] = './file/';
$config['allowed_types'] = 'pdf|php|html|js|xml|pptx|docx|xlsx|txt';
$config['file_name'] = 'file_'.time();
$this->upload->initialize($config);
if (!$this->upload->do_upload('file')) {
echo "<script>alert('Ulangi Lagi !!')
window.location='".base_url()."';
</script>";
}else{
$file = $this->upload->data();
$this->db->insert('tb_file',[
'nama_baru'=>$file['file_name'],
'nama_ori'=>$file['client_name']
]);
redirect(base_url());
}
}
function edit($id){
$res = $this->db->get_where('tb_file',['id_file'=>$id])->result_array();
$this->load->view('edit_file',['res'=>$res]);
}
}