code: static public function generateFilename($directory, $extension, $length = 16)
      {
          do {
              $name = \Extlib\Generator::generate($length);
              $filepath = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . sprintf('%s.%s', $name, $extension);
          } while (file_exists($filepath));
  
          return $name;
      }
docs: Return unique filename for directory
  
  @param string $directory
  @param string $extension
  @param  $length
  @return string