If it is only accurate to seconds, you can use the time() function result.
In order to avoid duplication at all, even if multiple files are uploaded within one second, a 3-digit random number should be added. The code is as follows:
$fname=time(). rand(100,999);
Or:
$fname=date('YmdHis').rand(100,999);