do {
  $name = sprintf('%s%03d.%s', date('YmdHis'), rand(0, 999), $ext) ;
}while(file_exists($name));