Advertisement
freddy0512

upload

Nov 4th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Upload_File extends CI_Controller {
  4.  
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->model('crud_model','crud'); //load model dari crud model dan diberi alias dengan nama crud
  9. $this->load->library('upload'); //load library upload bisa dilakukan disni atau disimpan di autoload
  10. }
  11.  
  12. public function index()
  13. {
  14. $this->load->view('form_upload'); //menampilkan halaman upload
  15. }
  16. public function do_upload()
  17. {
  18. $config['upload_path'] = "./image/"; //lokasi folder yang akan digunakan untuk menyimpan file
  19. $config['allowed_types'] = 'gif|jpg|png|JPEG'; //extension yang diperbolehkan untuk diupload
  20. $config['file_name'] = url_title($this->input->post('file_upload'));
  21.  
  22. $this->upload->initialize($config); //meng set config yang sudah di atur
  23. if( !$this->upload->do_upload('file_upload'))
  24. {
  25. echo $this->upload->display_errors();
  26. }
  27. else{
  28. $data = array(
  29. 'name'=>$this->upload->file_name
  30. );
  31. $this->crud->insert($data,'images');
  32. redirect('upload_file/view');
  33. }
  34. }
  35. public function view()
  36. {
  37. $data['images'] = $this->crud->show('images');
  38. $this->load->view('view_upload',$data);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement