php-doc-en/reference/filesystem/functions/tempnam.xml

96 lines
2.9 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.tempnam">
<refnamediv>
<refname>tempnam</refname>
<refpurpose>Create file with unique file name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>tempnam</methodname>
<methodparam><type>string</type><parameter>dir</parameter></methodparam>
<methodparam><type>string</type><parameter>prefix</parameter></methodparam>
</methodsynopsis>
<para>
Creates a file with a unique filename in the specified directory.
If the directory does not exist, <function>tempnam</function> may
generate a file in the system's temporary directory, and return
the name of that.
</para>
<para>
Prior to PHP 4.0.6, the behaviour of the
<function>tempnam</function> function was system dependent. On
Windows the TMP environment variable will override the
<parameter>dir</parameter> parameter, on Linux the TMPDIR
environment variable has precedence, while SVR4 will always use
your <parameter>dir</parameter> parameter if the directory it
points to exists. Consult your system documentation on the
tempnam(3) function if in doubt.
</para>
<note>
<simpara>
If PHP cannot create a file in the specified <parameter>dir</parameter>
parameter, it falls back on the system default.
</simpara>
</note>
<para>
Returns the new temporary filename, or &false; on
failure.
<example>
<title><function>tempnam</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$tmpfname = tempnam("/tmp", "FOO");
$handle = fopen($tmpfname, "w");
fwrite($handle, "writing to tempfile");
fclose($handle);
// do here something
unlink($tmpfname);
?>
]]>
</programlisting>
</example>
</para>
<note>
<simpara>
This function's behavior changed in 4.0.3. The temporary file is also
created to avoid a race condition where the file might appear in the
filesystem between the time the string was generated and before
the script gets around to creating the file. Note, that you need
to remove the file in case you need it no more, it is not done
automatically.
</simpara>
</note>
<para>
See also <function>tmpfile</function> and <function>unlink</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->