motters / image-safe
确保文件符合一组规格,是有效的图像文件。
dev-master
2016-06-25 22:39 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-26 00:10:51 UTC
README
当您想验证只限于图像的文件上传时使用!
主流框架提供的基线验证不足且不安全。这就是我向社区提供这个包的原因。
使用
public function uploadImageSafe()
{
//Start image safe validation
$v = new Motters\ImageSafe\ImageSafe();
//Set the rules for image safe
$validationRules = [
//Types of mimes that are allowed
'Mimes', // Optional settings ['allowed'=>['image/jpeg; charset=binary', 'image/jpg; charset=binary']]
//Make sure file name is aplha numerical (Files should always be renamed anway!)
'FileName', // Optional settings ['allowed'=>['-','_'], 'maximumCharacters'=>'100', 'minimumCharacters'=>'1']
//Minimum and maxium size of file image (Minimum file size will help stop denial of service attacks )
'FileSize', // Optional settings ['maximum'=>'2097152', 'minimum'=>'10240']
//Make sure the image has some valid and set dumensions
'DimensionSize', // Optional settings ['height'=>'1024', 'width'=>'768']
//Searches for elements in the images mimes that could potential be arbatry code, this is very beta!
'Characters', // ['unbanCharacters'=>['<?'], 'addbanCharacters'=>['<?'], 'addremoveCharacters'=>['<?'], 'unremoveCharacters'=>['<?']]
//Makes sure that the WHOLE image extention meets the below allowed white list
'FileExtension', // Optional settings ['allowed'=>['jpeg','jpeg.php']]
];
//Has validation passed or failed
if( $v->validate( $_FILES["image"], $validationRules ) )
{
//Passed upload image (Laravel Only Example)
$file = Input::file('image');
$fileName = $file->getClientOriginalName();
$fileDest = 'img';
$upload = Input::file('image')->move($fileDest, $fileName);
return Redirect::to('');
}
//Failed show some error message
dd('validation failed');
}
状态
积极开发,预计第一个稳定版本将在2016年1月20日发布
安全
如果您找到绕过此包保护的方法,请在GitHub上提交问题或通过sammottley@gmail.com给我发邮件。
待办事项
整理代码,编写测试,提供为什么这个库是必要的示例。
特别感谢
目前没有人。