Skip to content

Instantly share code, notes, and snippets.

@ssx
Created December 31, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssx/25a6bec6209348a5a024288c7a10c1d9 to your computer and use it in GitHub Desktop.
Save ssx/25a6bec6209348a5a024288c7a10c1d9 to your computer and use it in GitHub Desktop.
<?php
Route::get('/', function()
{
// Return our basic form view
return View::make("form");
});
Route::post('/', function()
{
// Build the input for our validation
$input = array('image' => Input::file('image'));
// Within the ruleset, make sure we let the validator know that this
// file should be an image
$rules = array(
'image' => 'image'
);
// Now pass the input and rules into the validator
$validator = Validator::make($input, $rules);
// Check to see if validation fails or passes
if ($validator->fails())
{
// Redirect with a helpful message to inform the user that
// the provided file was not an adequate type
return Redirect::to('/')->with('message', 'Error: The provided file was not an image');
} else
{
// Actually go and store the file now, then inform
// the user we successfully uploaded the file they chose
return Redirect::to('/')->with('message', 'Success: File upload was successful');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment