PHP/File Directory/Temporary file
Creating a temporary file in a particular place
<?php
$dir = dirname($existing_file);
$temp = tempnam($dir,"temp");
$temp_fh = fopen($temp,"w");
?>
Creating a temporary file with tempnam()
<?php
$tempfilename = tempnam("/tmp","data-");
$temp_fh = fopen($tempfilename,"w") or die($php_errormsg);
fputs($temp_fh,"The current time is ".strftime("%c"));
fclose($temp_fh) or die($php_errormsg);
?>
Creating a temporary file with tmpfile()
<?php
$temp_fh = tmpfile();
fputs($temp_fh,"The current time is ".strftime("%c"));
exit(1);
?>