2023-08-19 23:45:47 +05:30
|
|
|
<?php // Utility functions
|
|
|
|
|
|
|
|
// Check if request was to specified file
|
|
|
|
function ThisFileIsRequested ($fullpath): bool {
|
|
|
|
return substr($fullpath, -strlen($_SERVER["SCRIPT_NAME"])) === $_SERVER["SCRIPT_NAME"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate secure random string
|
|
|
|
function GenerateRandomString (int $length, string $keyspace = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"): string {
|
|
|
|
if ($length < 1) {
|
|
|
|
die("cant generate random string of size less than 1");
|
|
|
|
}
|
|
|
|
$pieces = [];
|
|
|
|
$max = mb_strlen($keyspace, "8bit") - 1;
|
|
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
|
|
$pieces []= $keyspace[random_int(0, $max)];
|
|
|
|
}
|
|
|
|
return implode('', $pieces);
|
|
|
|
}
|
|
|
|
|
2023-09-08 01:35:23 +05:30
|
|
|
// Get aspect ratio from width and height
|
|
|
|
function GetAspectRatio ($x, $y) {
|
|
|
|
if ($x === $y)
|
|
|
|
return 1;
|
|
|
|
return max($x, $y) / min($x, $y);
|
|
|
|
}
|
|
|
|
|
2023-08-19 23:45:47 +05:30
|
|
|
?>
|