Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function postChangeAvatar()
- {
- // Fields to be validated.
- $fields = array('avatar');
- $inputs = array('avatar' => Input::file('avatar'));
- if ( ! UserForm::is_valid($fields))
- {
- return Redirect::to('hesap/avatar')->withErrors(UserForm::$validation);
- }
- $file = Input::file('avatar');
- // File info...
- $file_name = $file->getClientOriginalName();
- $file_ext = $file->getClientOriginalExtension();
- $salt_name = str_replace($file_ext, '', $file_name);
- $sanitized = Str::slug($salt_name) . '.' . $file_ext;
- $path = 'img/avatars/' . Str::lower($this->user->username);
- if (Str::length($sanitized) <= 60)
- {
- // Remove the folder, even if it's empty.
- // (This is to check a folder shouldn't have more than one file)
- File::cleanDirectory($path);
- // Now, upload the avatar.
- $file->move($path, $sanitized);
- // Create a smaller version of the avatar.
- if (! File::isDirectory($path . '/small/')) File::makeDirectory($path . '/small/');
- Image::make($path . '/' . $sanitized)->resize(70, 70)->save($path . '/small/' . $sanitized);
- // Update the user's avatar path in the database.
- $this->user->avatar = $sanitized;
- $this->user->save();
- // Return feedback.
- $data['user_stuff'] = '<div class="feedback success">Avatar güncellendi.</div>';
- }
- else
- {
- $data['user_stuff'] = '<div class="feedback error">Dosya ismi çok uzun.</div>';
- }
- $this->layout->pageTitle = 'Proje :: Hesap Ayarları';
- $this->layout->content = View::make('templates.user.account', $data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement