forked from leftypol/leftypol
post.php: rework file image check
This commit is contained in:
parent
2b0473c2b8
commit
60119ddbe4
1 changed files with 23 additions and 17 deletions
28
post.php
28
post.php
|
@ -1290,25 +1290,31 @@ function handle_post(Context $ctx)
|
|||
|
||||
try {
|
||||
$ret = Metadata\sniff_image($file['tmp_name']);
|
||||
if (\in_array($ret[2], Metadata\SUPPORTED_IMAGE_MIME_TYPES)) {
|
||||
$ext = Metadata\mime_to_ext($ret[2]);
|
||||
$file['is_an_image'] = !\in_array($ext, $config['allowed_ext_files']);
|
||||
if ($file['is_an_image']) {
|
||||
|
||||
// Is it some kind of supported image?
|
||||
if (\in_array($ret[2], Metadata\SUPPORTED_IMAGE_MIME_TYPES)) {
|
||||
// Is it allowed?
|
||||
if (!\in_array($ext, $config['allowed_ext'])) {
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
|
||||
$file['is_an_image'] = true;
|
||||
$file['width'] = $ret[0];
|
||||
$file['height'] = $ret[1];
|
||||
$file['mime'] = $ret[2];
|
||||
}
|
||||
}
|
||||
$file['is_an_image'] = false;
|
||||
} catch (\RuntimeException $e) {
|
||||
$file['is_an_image'] = false;
|
||||
}
|
||||
|
||||
if (!$file['is_an_image']) {
|
||||
} else {
|
||||
// Is it a supported file?
|
||||
if (!\in_array($file['extension'], $config['allowed_ext_files'])) {
|
||||
// Should be 'invalid media' really.
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
$file['is_an_image'] = false;
|
||||
}
|
||||
} catch (\RuntimeException $e) {
|
||||
$log = $ctx->get(LogDriver::class);
|
||||
$log->log(LogDriver::ERROR, "Error while sniffing file '{$e->getMessage()}'");
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
|
||||
// Truncate filename if it is too long
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue