Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. public function postChangeAvatar()
  2.     {
  3.         // Fields to be validated.
  4.         $fields     = array('avatar');
  5.         $inputs     = array('avatar' => Input::file('avatar'));
  6.  
  7.         if ( ! UserForm::is_valid($fields))
  8.         {
  9.             return Redirect::to('hesap/avatar')->withErrors(UserForm::$validation);
  10.         }
  11.  
  12.         $file = Input::file('avatar');
  13.         // File info...
  14.         $file_name  = $file->getClientOriginalName();
  15.         $file_ext   = $file->getClientOriginalExtension();
  16.         $salt_name  = str_replace($file_ext, '', $file_name);
  17.  
  18.         $sanitized  = Str::slug($salt_name) . '.' . $file_ext;
  19.            
  20.         $path       = 'img/avatars/' . Str::lower($this->user->username);
  21.    
  22.         if (Str::length($sanitized) <= 60)
  23.         {
  24.             // Remove the folder, even if it's empty.
  25.             // (This is to check a folder shouldn't have more than one file)
  26.             File::cleanDirectory($path);
  27.             // Now, upload the avatar.
  28.             $file->move($path, $sanitized);
  29.             // Create a smaller version of the avatar.
  30.             if (! File::isDirectory($path . '/small/')) File::makeDirectory($path . '/small/');
  31.            
  32.             Image::make($path . '/' . $sanitized)->resize(70, 70)->save($path . '/small/' . $sanitized);
  33.             // Update the user's avatar path in the database.
  34.             $this->user->avatar = $sanitized;
  35.             $this->user->save();
  36.             // Return feedback.
  37.             $data['user_stuff']     = '<div class="feedback success">Avatar güncellendi.</div>';
  38.         }
  39.         else
  40.         {
  41.             $data['user_stuff']     = '<div class="feedback error">Dosya ismi çok uzun.</div>';
  42.         }
  43.            
  44.         $this->layout->pageTitle    = 'Proje :: Hesap Ayarları';
  45.         $this->layout->content  = View::make('templates.user.account', $data);
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement