added upload_of validation rule.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
51
system/validation/rules/upload_of.php
Normal file
51
system/validation/rules/upload_of.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user