Created
February 8, 2014 21:14
-
-
Save lowe0292/8890481 to your computer and use it in GitHub Desktop.
Laravel image upload
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
//in the IssuesController | |
if (Input::hasFile('displayPicture')) | |
{ | |
//process file input | |
//TODO: Validate that this is an image | |
$newName = Uploader::processInputFilename(Input::file('displayPicture')->getClientOriginalName()); | |
try{ | |
Input::file('displayPicture')->move(public_path() . Config::get('upload.directory'), $newName); | |
} catch (FileException $e) { | |
return Redirect::back()->with('flash_error', "Your file could not be uploaded. Please try again")->withInput(); | |
} | |
$newFellow->displayPicturePath = Config::get('upload.directory') . '/' . $newName; | |
} | |
<?php | |
//uploader class | |
class Uploader { | |
public static function processInputFilename($filename){ | |
return time() . '-' . preg_replace('/\s+/', '-', $filename); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
photo example:
photo Array ( [name] => Screen Shot 2014-02-08 at 12.19.53 PM 1.png [type] => image/png [tmp_name] => /tmp/phpxDv10F [error] => 0 [size] => 138411 )