mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Screenshots/Upload
* use fileInfo to determine the filetype (getimagesize fails if the file is not an actual image)
This commit is contained in:
@@ -4,7 +4,7 @@ define('AOWOW_REVISION', 19);
|
||||
define('CLI', PHP_SAPI === 'cli');
|
||||
|
||||
|
||||
$reqExt = ['SimpleXML', 'gd', 'mysqli', 'mbstring'];
|
||||
$reqExt = ['SimpleXML', 'gd', 'mysqli', 'mbstring', 'fileinfo'];
|
||||
$error = '';
|
||||
foreach ($reqExt as $r)
|
||||
if (!extension_loaded($r))
|
||||
|
||||
@@ -299,23 +299,19 @@ class ScreenshotPage extends GenericPage
|
||||
return Lang::main('intError');
|
||||
}
|
||||
|
||||
// check if file is an image; allow jpeg, png
|
||||
$finfo = new finfo(FILEINFO_MIME); // fileInfo appends charset information and other nonsense
|
||||
$mime = $finfo->file($_FILES['screenshotfile']['tmp_name']);
|
||||
if (preg_match('/^image\/(png|jpe?g)/i', $mime, $m))
|
||||
$isPNG = $m[0] == 'image/png';
|
||||
else
|
||||
return Lang::screenshot('error', 'unkFormat');
|
||||
|
||||
// invalid file
|
||||
$is = getimagesize($_FILES['screenshotfile']['tmp_name']);
|
||||
if (!$is || empty($is['mime']))
|
||||
if (!$is)
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
|
||||
// allow jpeg, png
|
||||
switch ($is['mime'])
|
||||
{
|
||||
case 'image/png':
|
||||
$isPNG = true;
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
break;
|
||||
default:
|
||||
return Lang::screenshot('error', 'unkFormat');
|
||||
}
|
||||
|
||||
// size-missmatch: 4k UHD upper limit; 150px lower limit
|
||||
if ($is[0] < $this->minSize || $is[1] < $this->minSize)
|
||||
return Lang::screenshot('error', 'tooSmall');
|
||||
|
||||
Reference in New Issue
Block a user