The tempnam() function creates a temporary file with a unique filename in the specified directory.
PHP tempnam() Function has the following syntax.
tempnam(dir,prefix)
Parameter | Is Required | Description |
---|---|---|
dir | Required. | Directory of where to create the temp file |
prefix | Required. | Start of the filename |
This function returns the new temporary filename, or FALSE on failure.
If the specified directory does not exist, tempnam() may generate a file in the system's temporary directory.
<?php
echo tempnam("C:\test\testweb","TMP0");
?>
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.