Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6259

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create file with unique file name</title>

 </head>
 <body><div class="manualnavbar" 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" id="refsect1-function.tempnam-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>tempnam</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$dir</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$prefix</code></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,  <span class="function"><strong>tempnam()</strong></span> may
   generate a file in the system&#039;s temporary directory, and return
   the name of that.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.tempnam-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">dir</code></em></span>
     <dd>

      <p class="para">
       The directory where the temporary filename will be created.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">prefix</code></em></span>
     <dd>

      <p class="para">
       The prefix of the generated temporary filename.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        Windows uses only the first three characters of prefix.
       </span>
      </p></blockquote>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.tempnam-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the new temporary filename, or <strong><code>FALSE</code></strong> on
   failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.tempnam-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.0.6</td>
       <td>
        Prior to PHP 4.0.6, the behaviour of the
         <span class="function"><strong>tempnam()</strong></span> function was system dependent. On
        Windows the <var class="varname"><var class="varname">TMP</var></var> environment variable will override the
        <em><code class="parameter">dir</code></em> parameter, on Linux the <var class="varname"><var class="varname">TMPDIR</var></var>
        environment variable has precedence, while SVR4 will always use
        your <em><code class="parameter">dir</code></em> parameter if the directory it
        points to exists. Consult your system documentation on the
        tempnam(3) function if in doubt.
       </td>
      </tr>

      <tr>
       <td>4.0.3</td>
       <td>
        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>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.tempnam-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2434">
    <p><strong>Example #1  <span class="function"><strong>tempnam()</strong></span> example</strong></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" id="refsect1-function.tempnam-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    If PHP cannot create a file in the specified <em><code class="parameter">dir</code></em>
    parameter, it falls back on the system default. On NTFS this also happens
    if the specified <em><code class="parameter">dir</code></em> contains more than 65534 files.
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.tempnam-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.tmpfile.html" class="function" rel="rdfs-seeAlso">tmpfile()</a> - Creates a temporary file</span></li>
    <li class="member"> <span class="function"><a href="function.sys-get-temp-dir.html" class="function" rel="rdfs-seeAlso">sys_get_temp_dir()</a> - Returns directory path used for temporary files</span></li>
    <li class="member"> <span class="function"><a href="function.unlink.html" class="function" rel="rdfs-seeAlso">unlink()</a> - Deletes a file</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" 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>