@@ -584,15 +584,17 @@ public function isAbsolutePath(string $file)
584
584
*
585
585
* @param string $prefix The prefix of the generated temporary filename
586
586
* Note: Windows uses only the first three characters of prefix
587
+ * @param string $suffix The suffix of the generated temporary filename
587
588
*
588
589
* @return string The new temporary filename (with path), or throw an exception on failure
589
590
*/
590
- public function tempnam (string $ dir , string $ prefix )
591
+ public function tempnam (string $ dir , string $ prefix/*, string $suffix = ''*/ )
591
592
{
593
+ $ suffix = \func_num_args () > 2 ? func_get_arg (2 ) : '' ;
592
594
list ($ scheme , $ hierarchy ) = $ this ->getSchemeAndHierarchy ($ dir );
593
595
594
596
// 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 ) {
596
598
$ tmpFile = @tempnam ($ hierarchy , $ prefix );
597
599
598
600
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
@@ -610,7 +612,7 @@ public function tempnam(string $dir, string $prefix)
610
612
// Loop until we create a valid temp file or have reached 10 attempts
611
613
for ($ i = 0 ; $ i < 10 ; ++$ i ) {
612
614
// Create a unique filename
613
- $ tmpFile = $ dir .'/ ' .$ prefix .uniqid (mt_rand (), true );
615
+ $ tmpFile = $ dir .'/ ' .$ prefix .uniqid (mt_rand (), true ). $ suffix ;
614
616
615
617
// Use fopen instead of file_exists as some streams do not support stat
616
618
// Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
0 commit comments