How it’s possible?
@mrrobot993 Because you’re just sticking the extension (tmp) on the end of the original filename (foo.jpg):
$filename = time() . '_' . $avatar->getClientOriginalName() . $avatar->getExtension();
Read the docs on how you should be storing uploaded files: https://laravel.com/docs/9.x/requests#storing-uploaded-files
You should not be manually creating filenames and manually put files like you are. All you need to do is:
$path = $request->file('avatar')->store('avatars');
That will store the file in your application’s storage/app/avatars directory. You shouldn’t be just putting anything user-uploaded in your public directory, because if a user uploads an 8 MB image then your app is just going to keep serving that same 8 MB image back, which isn’t performant at all. Or even worse, if a user manages to upload a malicious file then congratulations, because it’s publicly-accessible the user can now access the file and now potentially hack your server.
Store files somewhere that isn’t publicly-accessible. Then use something like Glide to serve appropriately-sized thumbnails instead.