mirror of
https://github.com/typemill/typemill.git
synced 2025-08-05 13:47:37 +02:00
V2.1.0 Fix fileupload error mtype check
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 120 KiB |
@@ -221,17 +221,19 @@ class ControllerApiFile extends Controller
|
||||
# if the previous check of the mtype with the base64 string failed, then do it now again with the temporary file
|
||||
if(!$mtype)
|
||||
{
|
||||
$fullPath = $this->settings['rootPath'] . $filePath;
|
||||
$filePath = str_replace('media/files', 'media/tmp', $fileinfo['url']);
|
||||
$filePath = str_replace('/', DIRECTORY_SEPARATOR, $filePath);
|
||||
$fullPath = $this->settings['rootPath'] . DIRECTORY_SEPARATOR . $filePath;
|
||||
$finfo = finfo_open( FILEINFO_MIME_TYPE );
|
||||
$mtype = @finfo_file( $finfo, $fullPath );
|
||||
finfo_close($finfo);
|
||||
|
||||
if(!$mtype OR !$this->checkAllowedMimeTypes($mtype, $extension))
|
||||
{
|
||||
$media->clearTempFolder();
|
||||
$media->clearTempFolder($immediate = true);
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'message' => Translations::translate('The mime-type is missing, not allowed or does not fit to the file extension.')
|
||||
'message' => Translations::translate('The mime-type is missing, not allowed or does not fit to the file extension.') . ' mtype: ' . $mtype . ', ext: ' . $extension
|
||||
]));
|
||||
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
|
||||
|
@@ -41,7 +41,7 @@ class Media
|
||||
$this->tmpFolder = $this->basepath . 'media' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
public function clearTempFolder()
|
||||
public function clearTempFolder($immediate = NULL)
|
||||
{
|
||||
$files = scandir($this->tmpFolder);
|
||||
$now = time();
|
||||
@@ -54,13 +54,15 @@ class Media
|
||||
$filelink = $this->tmpFolder . $file;
|
||||
if(file_exists($filelink))
|
||||
{
|
||||
$filetime = filemtime($filelink);
|
||||
if($now - $filetime > 1800)
|
||||
$filetime = filemtime($filelink);
|
||||
$delete = $immediate ? $immediate : ($now - $filetime > 1800);
|
||||
|
||||
if($delete)
|
||||
{
|
||||
if(!unlink($filelink))
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user