@@ -584,15 +584,17 @@ public function isAbsolutePath(string $file)
584584 *
585585 * @param string $prefix The prefix of the generated temporary filename
586586 * Note: Windows uses only the first three characters of prefix
587+ * @param string $suffix The suffix of the generated temporary filename
587588 *
588589 * @return string The new temporary filename (with path), or throw an exception on failure
589590 */
590- public function tempnam (string $ dir , string $ prefix )
591+ public function tempnam (string $ dir , string $ prefix/*, string $suffix = ''*/ )
591592 {
593+ $ suffix = \func_num_args () > 2 ? func_get_arg (2 ) : '' ;
592594 list ($ scheme , $ hierarchy ) = $ this ->getSchemeAndHierarchy ($ dir );
593595
594596 // If no scheme or scheme is "file" or "gs" (Google Cloud) create temp file in local filesystem
595- if (null === $ scheme || 'file ' === $ scheme || 'gs ' === $ scheme ) {
597+ if (( null === $ scheme || 'file ' === $ scheme || 'gs ' === $ scheme) && '' === $ suffix ) {
596598 $ tmpFile = @tempnam ($ hierarchy , $ prefix );
597599
598600 // If tempnam failed or no scheme return the filename otherwise prepend the scheme
@@ -610,7 +612,7 @@ public function tempnam(string $dir, string $prefix)
610612 // Loop until we create a valid temp file or have reached 10 attempts
611613 for ($ i = 0 ; $ i < 10 ; ++$ i ) {
612614 // Create a unique filename
613- $ tmpFile = $ dir .'/ ' .$ prefix .uniqid (mt_rand (), true );
615+ $ tmpFile = $ dir .'/ ' .$ prefix .uniqid (mt_rand (), true ). $ suffix ;
614616
615617 // Use fopen instead of file_exists as some streams do not support stat
616618 // Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
0 commit comments