diff --git a/media/files/screenshot-2023-06-09-at-16-53-35-typemill.png b/media/files/screenshot-2023-06-09-at-16-53-35-typemill.png deleted file mode 100644 index c8a20da..0000000 Binary files a/media/files/screenshot-2023-06-09-at-16-53-35-typemill.png and /dev/null differ diff --git a/system/typemill/Controllers/ControllerApiFile.php b/system/typemill/Controllers/ControllerApiFile.php index f2c1f34..7a64121 100644 --- a/system/typemill/Controllers/ControllerApiFile.php +++ b/system/typemill/Controllers/ControllerApiFile.php @@ -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); diff --git a/system/typemill/Models/Media.php b/system/typemill/Models/Media.php index d9d6f1c..75a8505 100644 --- a/system/typemill/Models/Media.php +++ b/system/typemill/Models/Media.php @@ -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; - } + } } } }