Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function change_avatar($id = null){
- $this->User->id = $id;
- if(!empty($this->request->data))
- {
- //Check if image has been uploaded
- if(!empty($this->request->data['User']['avatar']['name']))
- {
- $file = $this->request->data['User']['avatar']; //put the data into a var for easy use
- $ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
- $arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions
- //only process if the extension is valid
- if(in_array($ext, $arr_ext))
- {
- //do the actual uploading of the file. First arg is the tmp name, second arg is
- //where we are putting it
- move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/avatars/' . $file['name']);
- //prepare the filename for database entry
- $this->request->data['User']['avatar'] = $file['name'];
- }
- }
- //now do the save
- if ($this->request->is('post') || $this->request->is('put')) {
- $this->User->save($this->request->data);
- }
- // return $this->redirect(array('controller' => 'Forums', 'action' => 'index'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement