Added new example for touch()

Added two examples for stat()


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@265705 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kalle Sommer Nielsen 2008-08-31 01:30:39 +00:00
parent 44c0b43f25
commit fce226114f
2 changed files with 106 additions and 2 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.22 $ -->
<!-- $Revision: 1.23 $ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.stat">
<refnamediv>
<refname>stat</refname>
@ -166,6 +166,77 @@
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>stat</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
/* Get file stat */
$stat = stat('C:\php\php.exe');
/*
* Print file access file, this is the same
* as calling fileatime()
*/
echo 'Access time: ' . $stat['atime'];
/*
* Print file modification time, this is the
* same as calling filemtime()
*/
echo 'Modification time: ' . $stat['mtime'];
/* Print the device number */
echo 'Device number: ' . $stat['dev'];
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Using <function>stat</function> information together with <function>touch</function></title>
<programlisting role="php">
<![CDATA[
<?php
/* Get file stat */
$stat = @stat('C:\php\php.exe');
/* Did we failed to get stat information ? */
if(!$stat)
{
die('Stat call failed, aborting...');
}
/*
* Like in the example for touch() we'll need to
* set the timezone to prevent E_STRICT errors in
* PHP 5.1+
*/
if(function_exists('date_default_timezone_set'))
{
date_default_timezone_set('UTC');
}
/* We want the access time to be 1 week ago */
$atime = $stat['atime'] + 604800;
/* Touch the file */
if(!@touch('some_file.txt', time(), $atime))
{
die('Failed to touch file...');
}
echo 'Touch returned success...';
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.filesystem-time-res;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.touch">
<refnamediv>
<refname>touch</refname>
@ -106,6 +106,39 @@ if (touch($FileName)) {
echo "Sorry, could not change modification time of $FileName";
}
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>touch</function> using the <parameter>time</parameter> parameter</title>
<programlisting role="php">
<![CDATA[
<?php
/*
* First set the time zone if PHP 5.1+, this will
* prevent any E_STRICT errors.
*/
if(function_exists('date_default_timezone_set'))
{
date_default_timezone_set('UTC');
}
/*
* Next is the touch time, we'll set it to one hour
* in the past.
*/
$time = time() - 3600;
/* Touch the file */
if(!touch('some_file.txt', $time))
{
die('Whoops, something went wrong...');
}
echo 'Touched file with success';
?>
]]>
</programlisting>
</example>