Guest User

Untitled

a guest
Apr 26th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. function update(){
  4. $data['title'] = "Update Artikel";
  5. $data['session_user'] = $this->session_user;
  6. if(empty($this->uri->segment('3'))){ redirect('articles');}
  7. $id = $this->uri->segment('3');
  8. $data['articles'] = $this->articlesModel->getArticleWhere($id);
  9. $this->load->library('upload');
  10.  
  11. if(count($_POST)){
  12. $title = str_replace(' ','-',$this->input->post('title'));
  13. $config['upload_path'] = './public/images/articles'; //path folder
  14. $config['allowed_types'] = 'jpg|png|jpeg'; //type yang dapat diakses bisa anda sesuaikan
  15. $config['file_name'] = $title.'_img.jpg'; //nama yang terupload nantinya
  16. $config['overwrite'] = true;
  17. $this->upload->initialize($config);
  18. if(!empty($_FILES['image']['name'])){
  19. if ($this->upload->do_upload('image'))
  20. {
  21. $img = $this->upload->data();
  22. $image = $img['file_name'];
  23. $data['notif'] = $this->articlesModel->updateArticles($id,$image);
  24. }
  25. }else{
  26. $data['notif'] = $this->articlesModel->updateArticles($id,$this->input->post('oldImage'));
  27. }
  28.  
  29. if($data['notif']['type'] == 'success'){
  30. $data['articles'] = '';
  31. echo '<script>setTimeout(function(){ window.location.href = "'.base_url('articles').'"; }, 1000);</script>';
  32. }
  33.  
  34. }
  35.  
  36. $this->load->view('includes/header', $data);
  37. $this->load->view('dashboard/article_edit', $data);
  38. $this->load->view('includes/footer', $data);
  39. }
Add Comment
Please, Sign In to add comment