mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进上传文件验证
This commit is contained in:
@@ -681,21 +681,17 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileExt($file, $rule)
|
protected function fileExt($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof File)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (is_string($rule)) {
|
|
||||||
$rule = explode(',', $rule);
|
|
||||||
}
|
|
||||||
if (is_array($file)) {
|
if (is_array($file)) {
|
||||||
foreach ($file as $item) {
|
foreach ($file as $item) {
|
||||||
if (!$item->checkExt($rule)) {
|
if (!($item instanceof File) || !$item->checkExt($rule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} elseif ($file instanceof File) {
|
||||||
return $file->checkExt($rule);
|
return $file->checkExt($rule);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,21 +704,17 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileMime($file, $rule)
|
protected function fileMime($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof File)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (is_string($rule)) {
|
|
||||||
$rule = explode(',', $rule);
|
|
||||||
}
|
|
||||||
if (is_array($file)) {
|
if (is_array($file)) {
|
||||||
foreach ($file as $item) {
|
foreach ($file as $item) {
|
||||||
if (!$item->checkMime($rule)) {
|
if (!($item instanceof File) || !$item->checkMime($rule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} elseif ($file instanceof File) {
|
||||||
return $file->checkMime($rule);
|
return $file->checkMime($rule);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -735,18 +727,17 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileSize($file, $rule)
|
protected function fileSize($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof File)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (is_array($file)) {
|
if (is_array($file)) {
|
||||||
foreach ($file as $item) {
|
foreach ($file as $item) {
|
||||||
if (!$item->checkSize($rule)) {
|
if (!($item instanceof File) || !$item->checkSize($rule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} elseif ($file instanceof File) {
|
||||||
return $file->checkSize($rule);
|
return $file->checkSize($rule);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user