Commit abfaeaff authored by Taylor Otwell's avatar Taylor Otwell

added upload_of validation rule.

parent 0b7dbab0
......@@ -69,6 +69,18 @@ class Input {
return Arr::get(Session::get('laravel_old_input', array()), $key, $default);
}
/**
* Get an item from the uploaded file data.
*
* @param string $key
* @param mixed $default
* @return array
*/
public static function file($key, $default = null)
{
return Arr::get($_FILES, $key, $default);
}
/**
* Hydrate the input data for the request.
*
......
<?php namespace System\Validation\Rules;
use System\Input;
use System\Validation\Rule;
class Upload_Of extends Rule {
/**
* The acceptable file extensions.
*
* @var array
*/
public $extensions;
/**
* The maximum file size in bytes.
*
* @var int
*/
public $maximum;
/**
* Evaluate the validity of an attribute.
*
* @param string $attribute
* @param array $attributes
* @return void
*/
public function check($attribute, $attributes)
{
if ( ! array_key_exists($attribute, Input::file()))
{
return true;
}
$file = Input::file($attribute);
if ( ! is_null($this->maximum) and $file['size'] > $this->maximum)
{
return false;
}
if ( ! is_null($this->extensions) and ! in_array(File::extension($file['name']), $this->extensions))
{
return false;
}
return true;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment