In this article, you will learn how to create a temporary file in PHP. The tempnam() function in PHP creates a temporary file with a unique name in the specified directory. It creates a file in the system temporary directory if the specified directory does not exist.
what is the syntax of the TEMPNAM function in php?
tempnam(dir, prefix)
Parameter | Description |
---|---|
dir | Required. Specifies the directory of where to create the temp file |
prefix | Required. Specifies the start of the filename |
examples of the TEMPNAM function
Example 1. In this example, we create a temporary file with a unique name in the specified directory.
<?php
echo tempnam("C:\inetpub\testweb","TMP0");
?>