Thursday, October 9, 2025
HomeLanguagesPHP sys_get_temp_dir() Function

PHP sys_get_temp_dir() Function

The sys_get_temp_dir() is an inbuilt function where the directory path for temporary files will be returned.

Syntax:

sys_get_temp_dir()

Parameter: This function doesn’t accept any parameter.

Return Value: This function returns the path for the temporary directory.

Example 1: This code demonstrates the sys_get_temp_dir() function.

PHP




<?php 
   // print tmp location
   echo sys_get_temp_dir();
?>


Output:

/tmp

Example 2: This is another code that demonstrates the sys_get_temp_dir() function.

PHP




<?php
  $temp_file = tempnam(sys_get_temp_dir(), 'gfg');
  echo $temp_file;
?>


Output:

/tmp/gfgluzYqw 

Reference: https://www.php.net/manual/en/function.sys-get-temp-dir.php

RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS