<!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>Sets access and modification time of file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.tmpfile.html">tmpfile</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.umask.html">umask</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.touch" class="refentry"> <div class="refnamediv"> <h1 class="refname">touch</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">touch</span> — <span class="dc-title">Sets access and modification time of file</span></p> </div> <div class="refsect1 description" id="refsect1-function.touch-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>touch</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$time</code><span class="initializer"> = time()</span></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$atime</code></span> ]] )</div> <p class="para rdfs-comment"> Attempts to set the access and modification times of the file named in the <em><code class="parameter">filename</code></em> parameter to the value given in <em><code class="parameter">time</code></em>. Note that the access time is always modified, regardless of the number of parameters. </p> <p class="para"> If the file does not exist, it will be created. </p> </div> <div class="refsect1 parameters" id="refsect1-function.touch-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> The name of the file being touched. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">time</code></em></span> <dd> <p class="para"> The touch time. If <em><code class="parameter">time</code></em> is not supplied, the current system time is used. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">atime</code></em></span> <dd> <p class="para"> If present, the access time of the given filename is set to the value of <em><code class="parameter">atime</code></em>. Otherwise, it is set to the value passed to the <em><code class="parameter">time</code></em> parameter. If neither are present, the current system time is used. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.touch-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 changelog" id="refsect1-function.touch-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>5.3.0</td> <td> It became possible to change the modification time of a directory under Windows. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.touch-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2436"> <p><strong>Example #1 <span class="function"><strong>touch()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #0000BB">$filename </span><span style="color: #007700">. </span><span style="color: #DD0000">' modification time has been changed to present time'</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">'Sorry, could not change modification time of ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$filename</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2437"> <p><strong>Example #2 <span class="function"><strong>touch()</strong></span> using the <em><code class="parameter">time</code></em> parameter</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// This is the touch time, we'll set it to one hour in the past.<br /></span><span style="color: #0000BB">$time </span><span style="color: #007700">= </span><span style="color: #0000BB">time</span><span style="color: #007700">() - </span><span style="color: #0000BB">3600</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Touch the file<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_file.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">$time</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">'Whoops, something went wrong...'</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">'Touched file with success'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.touch-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">Note that time resolution may differ from one file system to another.</p></p></blockquote> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> Prior to PHP 5.3.0 it was not possible to change the modification time of a directory with this function under Windows. </p> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.tmpfile.html">tmpfile</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.umask.html">umask</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>