Skip to content

Instantly share code, notes, and snippets.

@lowe0292
Created February 8, 2014 21:14
Show Gist options
  • Save lowe0292/8890481 to your computer and use it in GitHub Desktop.
Save lowe0292/8890481 to your computer and use it in GitHub Desktop.
Laravel image upload
//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);
}
}
@csain
Copy link

csain commented Feb 8, 2014

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment