$USER_AGENT = filter_var($_SERVER['HTTP_USER_AGENT'], FILTER_SANITIZE_ENCODED);
$ip = null;
if ($this->Connector->CONFIG['LOG_IP']) {
- $ip = $_SERVER['REMOTE_ADDR'];
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
}
$this->fingerPrintInfo = [
'timestamp' => time(),
*
* @return string The file extension of the file.
*/
- public function fileExtension(array $file):?string
+ public function fileExtension(array $file):string
{
- if(str_contains($file['name'], '.')){
$extension = explode('.', $file['name']);
- $dotCount = substr_count($file['name'], '.');
+ $dotCount = substr_count($file['name'], '.');
return match ($dotCount) {
+ 0 => $this->lookupExtension($file['type']),
1 => end($extension),
2 => $this->doubleDotExtension($extension),
default => end($extension)
};
- }
- return "NOEXT";
}
/**
$index = rand(0, strlen($this->Connector->CONFIG['ID_CHARSET']) - 1);
$NEW_NAME .= $this->Connector->CONFIG['ID_CHARSET'][$index];
}
- if ($extension != "NOEXT") {
+ if (!empty($extension)) {
$NEW_NAME .= '.' . $extension;
}
} while ($this->Connector->dbCheckNameExists($NEW_NAME));
return $NEW_NAME;
}
+
+ private function lookupExtension(string $mimetype):string
+ {
+ $types = [
+ 'image/gif' => 'gif',
+ 'image/jpeg' => 'jpg',
+ 'image/avif' => 'avif',
+ 'image/png' => 'png',
+ 'image/tiff' => 'tiff',
+ 'image/vnd.wap.wbmp' => 'wbmp',
+ 'image/webp' => 'webp',
+ 'image/x-icon' => 'ico',
+ 'image/x-jng' => 'jng',
+ 'image/x-ms-bmp' => 'bmp',
+ 'application/pdf' => 'pdf',
+ 'application/postscript' => 'ps',
+ 'application/x-7z-compressed' => '7z',
+ 'application/zip' => 'zip',
+ 'audio/midi' => 'mid',
+ 'audio/mpeg' => 'mp3',
+ 'audio/ogg' => 'ogg',
+ 'audio/x-m4a' => 'm4a',
+ 'audio/x-realaudio' => 'ra',
+ 'video/3gpp' => '3gpp',
+ 'video/mp2t' => 'ts',
+ 'video/mp4' => 'mp4',
+ 'video/mpeg' => 'mpeg',
+ 'video/quicktime' => 'mov',
+ 'video/webm' => 'webm',
+ 'video/x-flv' => 'flv',
+ 'video/x-m4v' => 'm4v',
+ 'video/x-mng' => 'mng',
+ 'video/x-ms-asf' => 'asx',
+ 'video/x-ms-wmv' => 'wmv',
+ 'video/x-msvideo' => 'avi',
+ ];
+ if (isset($types[$mimetype])) {
+ return $types[$mimetype];
+ } else {
+ $this->Connector->response->error(400, 'Unknown MIME type. Add a file extension to your filename.');
+ }
+ }
}