Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public function change_avatar($id = null){
  2. $this->User->id = $id;
  3.  
  4. if(!empty($this->request->data))
  5. {
  6. //Check if image has been uploaded
  7. if(!empty($this->request->data['User']['avatar']['name']))
  8. {
  9. $file = $this->request->data['User']['avatar']; //put the data into a var for easy use
  10.  
  11. $ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
  12. $arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions
  13.  
  14.  
  15. //only process if the extension is valid
  16. if(in_array($ext, $arr_ext))
  17. {
  18. //do the actual uploading of the file. First arg is the tmp name, second arg is
  19. //where we are putting it
  20. move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/avatars/' . $file['name']);
  21.  
  22. //prepare the filename for database entry
  23. $this->request->data['User']['avatar'] = $file['name'];
  24. }
  25. }
  26.  
  27. //now do the save
  28. if ($this->request->is('post') || $this->request->is('put')) {
  29. $this->User->save($this->request->data);
  30. }
  31. // return $this->redirect(array('controller' => 'Forums', 'action' => 'index'));
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement