I have a form where I am uploading images and I want the hash which is generated as the filename for the uploaded image to be collision free. Now I want to know if the way I am doing it is safe.
This is the function which is handling this. The file class is using the Str::random function so not very safe, right?
protected function uploadFile(UploadedFile|File $logo): ?String
{
return Storage::putFile('company/logos', $logo);
}
The chance of collision is very low. But, you can also use putFileAs with unique name generated via algorithms like UUID or other unique identifier generators. With which, the collision chance is miniscule.