public static function upload($file)
{
$path = 'tmp' . time();
$absolute_path = storage_path("textures/{$path}");
try {
if (false === move_uploaded_file($file['tmp_name'], $absolute_path)) {
throw new \Exception('Failed to remove uploaded files, please check the permission', 1);
}
} catch (\Exception $e) {
Log::warning("Failed to move uploaded file, {$e}");
} finally {
if (file_exists($absolute_path)) {
$hash = hash_file('sha256', $absolute_path);
if (!Storage::disk('textures')->has($hash)) {
Storage::disk('textures')->move($path, $hash);
} else {
// delete the temp file
unlink($absolute_path);
}
return $hash;
} else {
Log::warning("Failed to upload file {$path}");
}
}
}