private function moveUploadedFile(string $tmp_name) : string
{
$dir1 = \Sodium\bin2hex(\random_bytes(1));
$dir2 = \Sodium\bin2hex(\random_bytes(1));
$base = AIRSHIP_UPLOADS . $dir1 . DIRECTORY_SEPARATOR . $dir2;
if (!\file_exists($base)) {
\mkdir($base, 0775, true);
}
do {
$filename = \Sodium\bin2hex(\random_bytes(22));
} while (\file_exists($base . DIRECTORY_SEPARATOR . $filename));
if (!\move_uploaded_file($tmp_name, $base . DIRECTORY_SEPARATOR . $filename)) {
throw new UploadError(\__('Could not move temporary file to its permanent home'));
}
return $dir1 . DIRECTORY_SEPARATOR . $dir2 . DIRECTORY_SEPARATOR . $filename;
}