PHP Tutorial - PHP tempnam() Function






Definition

The tempnam() function creates a temporary file with a unique filename in the specified directory.

Syntax

PHP tempnam() Function has the following syntax.

tempnam(dir,prefix)

Parameter

ParameterIs RequiredDescription
dirRequired.Directory of where to create the temp file
prefixRequired.Start of the filename

Return

This function returns the new temporary filename, or FALSE on failure.





Note

If the specified directory does not exist, tempnam() may generate a file in the system's temporary directory.

Example


<?php
echo tempnam("C:\test\testweb","TMP0");
?>

Example 2

The following code shows how to create a temporary file with a unique filename in the specified directory.



<?php
    echo tempnam("C:/testweb/a/a/a/a/","TMP0");
?>

The code above generates the following result.