function.tempnam.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 182 行

HTML
182
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Create file with unique file name</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.symlink.html">symlink</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.tmpfile.html">tmpfile</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.tempnam" class="refentry"> <div class="refnamediv">  <h1 class="refname">tempnam</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">tempnam</span> &mdash; <span class="dc-title">Create file with unique file name</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">string</span> <span class="methodname"><b><b>tempnam</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$dir</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$prefix</tt></span>   )</div>  <p class="para rdfs-comment">   Creates a file with a unique filename, with access permission set to 0600, in the specified directory.   If the directory does not exist, <b>tempnam()</b> may   generate a file in the system&#039;s temporary directory, and return   the name of that.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">dir</tt></i></span>     <dd>      <p class="para">       The directory where the temporary filename will be created.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">prefix</tt></i></span>     <dd>      <p class="para">       The prefix of the generated temporary filename.      </p>     </dd>    </dt>   </dl>  </p> </div>  <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns the new temporary filename, or <b><tt>FALSE</tt></b> on   failure.  </p> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.0.6</td>       <td colspan="1" rowspan="1" align="left">        Prior to PHP 4.0.6, the behaviour of the        <b>tempnam()</b> function was system dependent. On        Windows the TMP environment variable will override the        <i><tt class="parameter">dir</tt></i> parameter, on Linux the TMPDIR        environment variable has precedence, while SVR4 will always use        your <i><tt class="parameter">dir</tt></i> parameter if the directory it        points to exists. Consult your system documentation on the        tempnam(3) function if in doubt.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.0.3</td>       <td colspan="1" rowspan="1" align="left">        This function&#039;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.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>tempnam()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$tmpfname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">tempnam</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"FOO"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$handle&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$tmpfname</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"writing&nbsp;to&nbsp;tempfile"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;do&nbsp;here&nbsp;something<br /><br /></span><span style="color: #0000BB">unlink</span><span style="color: #007700">(</span><span style="color: #0000BB">$tmpfname</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>:    <span class="simpara">    If PHP cannot create a file in the specified <i><tt class="parameter">dir</tt></i>    parameter, it falls back on the system default.   </span>  </p></blockquote> </div>  <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.tmpfile.html" class="function" rel="rdfs-seeAlso">tmpfile()</a></li>    <li class="member"><a href="function.sys-get-temp-dir.html" class="function" rel="rdfs-seeAlso">sys_get_temp_dir()</a></li>    <li class="member"><a href="function.unlink.html" class="function" rel="rdfs-seeAlso">unlink()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.symlink.html">symlink</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.tmpfile.html">tmpfile</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?