Created
September 25, 2012 08:11
-
-
Save sineld/3780572 to your computer and use it in GitHub Desktop.
Laravel File Upload And Resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Resizer and Image Manipulation | |
// Based on: http://forums.laravel.com/viewtopic.php?id=2648 | |
public function post_edit_logo($id) | |
{ | |
$rules = array( | |
'image' => 'image', | |
); | |
$validation = Validator::make(Input::file('logo'), $rules); | |
// create random filename | |
$filename = Str::random(20) .'.'. File::extension(Input::file('logo.name')); | |
// Save logo in the database | |
$event = Events::where('user_id', '=', $id)->first(); | |
$event->logo = $filename; | |
$event->save(); | |
// start bundle 'resizer' | |
Bundle::start('resizer'); | |
// resize image | |
$img = Input::file('logo'); | |
$success = Resizer::open($img) | |
->resize(60 , 30 , 'auto' ) | |
->save('public/uploads/thumbnails/'.$filename , 90 ); | |
// move uploaded file to public/uploads | |
Input::upload('logo', 'public/uploads', $filename); | |
} | |
?> |
Laravel no longer supports Bundle::start.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice tut.Do you have a snippet on how to upload files using laravel 4 and enable users to download the uploaded files?