Fixed tempnam() creates paths with '//'

Sync with PHP's implementation

Closes #3313
nit:

  if ((tmpdir.length() > 0) && (tempdir[tempdir.length() - 1] == '/')) {