uTools-Manuals/docs/php/touch.html
2019-04-08 23:22:26 +08:00

158 lines
6.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>设定文件的访问和修改时间</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.touch" class="refentry">
<div class="refnamediv">
<h1 class="refname">touch</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">touch</span> &mdash; <span class="dc-title">设定文件的访问和修改时间</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.touch-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<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>
]] ) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
尝试将由 <code class="parameter">filename</code>
给出的文件的访问和修改时间设定为给出的 <code class="parameter">time</code>
注意访问时间总是会被修改的,不论有几个参数。
</p>
<p class="para">
如果文件不存在,则会被创建。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.touch-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">filename</code></dt>
<dd>
<p class="para">
要设定的文件名。
</p>
</dd>
<dt>
<code class="parameter">time</code></dt>
<dd>
<p class="para">
要设定的时间。如果没有提供参数 <code class="parameter">time</code> 则会使用当前系统的时间。
</p>
</dd>
<dt>
<code class="parameter">atime</code></dt>
<dd>
<p class="para">
如果给出了这个参数,则给定文件的访问时间会被设为
<code class="parameter">atime</code>,否则会设置 为<code class="parameter">time</code>。如果没有给出这两个参数,则使用当前系统时间。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.touch-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.touch-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.0</td>
<td>
能够修改 Windows 下目录的最后修改时间。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.touch-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2849">
<p><strong>Example #1 <span class="function"><strong>touch()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$filename&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'&nbsp;modification&nbsp;time&nbsp;has&nbsp;been&nbsp;changed&nbsp;to&nbsp;present&nbsp;time'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Sorry,&nbsp;could&nbsp;not&nbsp;change&nbsp;modification&nbsp;time&nbsp;of&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$filename</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-2850">
<p><strong>Example #2 使用 <code class="parameter">time</code> 参数的 <span class="function"><strong>touch()</strong></span></strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;the&nbsp;touch&nbsp;time,&nbsp;we'll&nbsp;set&nbsp;it&nbsp;to&nbsp;one&nbsp;hour&nbsp;in&nbsp;the&nbsp;past.<br /></span><span style="color: #0000BB">$time&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()&nbsp;-&nbsp;</span><span style="color: #0000BB">3600</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Touch&nbsp;the&nbsp;file<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_file.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$time</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Whoops,&nbsp;something&nbsp;went&nbsp;wrong...'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Touched&nbsp;file&nbsp;with&nbsp;success'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.touch-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">注意:不同文件系统对时间的判断方法可能是不相同的。</p></p></blockquote>
<div class="warning"><strong class="warning">Warning</strong>
<p class="para">
在 PHP 5.3.0 之前无法修改 Windows 下目录的最后修改时间。
</p>
</div>
</div>
</div></div></div></body></html>