Jump to: navigation, search

Php tempnam

From w3cyberlearnings

Contents

PHP function tempnam

This function creates a temporary file with a unique name and having access permission sets to 0600 by default.

Syntax tempnam

  • dir: sets directory to create temp file
  • prefix: sets file prefix
tempnam(dir,prefix);

Note

User has to access permission to the directory to create a file.

Example 1

<?php 
   for($i=0; $i < 5; $i++ ) {
        echo tempnam('/home/sophal/testphp','aa_');
        echo "\n";
   }
?>

Output

sophal@sophal-desktop:~/testphp$ php tempnam.php
/home/sophal/testphp/aa_PtwHNn
/home/sophal/testphp/aa_87pRjt
/home/sophal/testphp/aa_2BD1Py
/home/sophal/testphp/aa_aHFcmE
/home/sophal/testphp/aa_Pq2nSJ

Example 2

Create a temporary file in a temporary directory(/tmp).

<?php 
   for($i=0; $i < 5; $i++ ) {
        echo tempnam(sys_get_temp_dir(),'bb_');
        echo "\n";
   }
?>

Output

sophal@sophal-desktop:~/testphp$ php tempnam.php
/tmp/bb_bCCDDq
/tmp/bb_HhDXYu
/tmp/bb_GU2hkz
/tmp/bb_EZQCFD
/tmp/bb_oC0X0H

Related Links


basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--

Navigation
Web
SQL
MISC
References