PHP tempnam() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The tempnam() function is an inbuilt function in PHP that helps in creating a file having a unique file name by setting the access permission to 0600, having the specified directory. This function then generates the file in the system's temporary directory, if the specified directory does not exist or is not writable. In that case, the full path to that specific file with its name will be returned. Syntax: tempnam(string $directory, string $prefix): string|falseParameters: This function accepts the following parameters: directory: This parameter specifies the directory that contains the created temporary filename.prefix: This parameter specifies the prefix of the generated temporary file name.Return Value: The unique filename with a path will be returned otherwise returns "false" on failure. Example 1: The following code demonstrates the PHP function tempnam() function. PHP <?php $tmpfname = tempnam( "/home/dachman/Desktop/Articles/GFG/Method/", "work"); $handle = fopen($tmpfname, "w"); fwrite($handle, "writing to tempfile"); fclose($handle); ?> Output: This creates a temporary file "work.txtOcB1ad" in the above directory, which when opened shows the following content. writing to tempfile Example 2: This is another code example that demonstrates the PHP tempnam() function. PHP <?php $tmpfname = tempnam( "/home/dachman/Desktop/Articles/GFG/Method/", "gfg"); if ($tmpfname) { echo "File is created with a unique name"; } else { echo "File is not created with a unique name"; } ?> Output: File is created with a unique name Reference: https://www.php.net/manual/en/function.tempnam.php Comment More infoAdvertise with us Next Article PHP tempnam() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Filesystem Similar Reads PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP strspn() Function The strspn() function is an in-built function in PHP which finds the length of the initial segment of a string consisting entirely of characters contained within a given list of characters passed as a parameter to the function. Syntax : strspn( $string, $charlist, $start, $length) Parameters : This 3 min read PHP strnatcmp() function The strnatcmp() is a built-in function on PHP. This function compares two strings using a "natural order" algorithm and return a positive integer, negative or zero. This function is case-sensitive. Syntax: strnatcmp( $string1, $string2 ) Parameters: The functions accepts two mandatory string paramet 2 min read PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time() Parameter: This function does not accepts any parameter 2 min read PHP trim() Function The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right. Related Functions: PHP | ltrim() Function PHP | rtrim() Function Syntax: trim($string, $charlist) Parameters:The function accepts one man 2 min read Like