cvs: phpdoc /en/reference/filesystem/functions fileatime.xml filectime.xml filesize.xml filetype.xml flock.xml fpassthru.xml fseek.xml fstat.xml
ftell.xml is-executable.xml link.xml linkinfo.xml readlink.xml

From: Date: Sat, 16 Aug 2003 21:42:14 +0000
Subject: cvs: phpdoc /en/reference/filesystem/functions fileatime.xml filectime.xml filesize.xml filetype.xml flock.xml fpassthru.xml fseek.xml fstat.xml
ftell.xml is-executable.xml link.xml linkinfo.xml readlink.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969355853@lists.php.net to get a copy of this message
didou Sat Aug 16 17:42:14 2003 EDT Modified files: /phpdoc/en/reference/filesystem/functions fileatime.xml filectime.xml filesize.xml filetype.xml flock.xml fpassthru.xml fseek.xml fstat.xml ftell.xml is-executable.xml link.xml linkinfo.xml readlink.xml Log: adding examples proposed by vincent at php dot net most of them are from users notes

Index: phpdoc/en/reference/filesystem/functions/fileatime.xml diff -u phpdoc/en/reference/filesystem/functions/fileatime.xml:1.3 phpdoc/en/reference/filesystem/functions/fileatime.xml:1.4 --- phpdoc/en/reference/filesystem/functions/fileatime.xml:1.3 Sat Feb 22 13:55:36 2003 +++ phpdoc/en/reference/filesystem/functions/fileatime.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.fileatime"> <refnamediv> @@ -31,6 +31,25 @@ &note.no-remote; + <para> + <example> + <title><function>fileatime</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// outputs e.g. somefile.txt was last accessed: December 29 2002 22:16:23. + +$filename = 'somefile.txt'; +if (file_exists($filename)) { + echo "$filename was last accessed: " . date ("F d Y H:i:s.", fileatime($filename)); +} + +?> +]]> + </programlisting> + </example> + </para> <simpara> See also <function>filemtime</function>, <function>fileinode</function>, and Index: phpdoc/en/reference/filesystem/functions/filectime.xml diff -u phpdoc/en/reference/filesystem/functions/filectime.xml:1.3 phpdoc/en/reference/filesystem/functions/filectime.xml:1.4 --- phpdoc/en/reference/filesystem/functions/filectime.xml:1.3 Sat Feb 22 13:55:36 2003 +++ phpdoc/en/reference/filesystem/functions/filectime.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.filectime"> <refnamediv> @@ -33,7 +33,26 @@ &note.clearstatcache; &note.no-remote; - + + <para> + <example> + <title><function>fileatime</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// outputs e.g. somefile.txt was last changed: December 29 2002 22:16:23. + +$filename = 'somefile.txt'; +if (file_exists($filename)) { + echo "$filename was last changed: " . date ("F d Y H:i:s.", filectime($filename)); +} + +?> +]]> + </programlisting> + </example> + </para> <simpara> See also <function>filemtime</function> </simpara> Index: phpdoc/en/reference/filesystem/functions/filesize.xml diff -u phpdoc/en/reference/filesystem/functions/filesize.xml:1.4 phpdoc/en/reference/filesystem/functions/filesize.xml:1.5 --- phpdoc/en/reference/filesystem/functions/filesize.xml:1.4 Tue Jun 3 16:51:26 2003 +++ phpdoc/en/reference/filesystem/functions/filesize.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.filesize"> <refnamediv> @@ -28,6 +28,23 @@ &note.no-remote; + <para> + <example> + <title><function>filesize</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// outputs e.g. somefile.txt: 1024 bytes + +$filename = 'somefile.txt'; +echo $filename . ': ' . filesize($filename) . ' bytes'; + +?> +]]> + </programlisting> + </example> + </para> <simpara> See also <function>file_exists</function> </simpara> Index: phpdoc/en/reference/filesystem/functions/filetype.xml diff -u phpdoc/en/reference/filesystem/functions/filetype.xml:1.8 phpdoc/en/reference/filesystem/functions/filetype.xml:1.9 --- phpdoc/en/reference/filesystem/functions/filetype.xml:1.8 Tue Jul 22 11:57:45 2003 +++ phpdoc/en/reference/filesystem/functions/filetype.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.filetype"> <refnamediv> @@ -26,8 +26,23 @@ &note.no-remote; + <para> + <example> + <title><function>filetype</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +echo filetype('/etc/passwd'); // file +echo filetype('/etc/'); // dir + +?> +]]> + </programlisting> + </example> + </para> <simpara> - See also: <function>is_dir</function>, <function>is_file</function>, + See also <function>is_dir</function>, <function>is_file</function>, <function>is_link</function>, <function>file_exists</function>, <function>stat</function>, and <function>mime_content_type</function>. </simpara> Index: phpdoc/en/reference/filesystem/functions/flock.xml diff -u phpdoc/en/reference/filesystem/functions/flock.xml:1.7 phpdoc/en/reference/filesystem/functions/flock.xml:1.8 --- phpdoc/en/reference/filesystem/functions/flock.xml:1.7 Mon Feb 10 15:18:18 2003 +++ phpdoc/en/reference/filesystem/functions/flock.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.7 $ --> +<!-- $Revision: 1.8 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.flock"> <refnamediv> @@ -67,6 +67,29 @@ <simpara> &return.success; </simpara> + <para> + <example> + <title><function>flock</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +$fp = fopen("/tmp/lock.txt", "w+"); + +if (flock($fp, LOCK_EX)) { // do an exclusive lock + fwrite($fp, "Write something here\n"); + flock($fp, LOCK_UN); // release the lock +} else { + echo "Couldn't lock the file !"; +} + +fclose($fp); + +?> +]]> + </programlisting> + </example> + </para> <note> <para> Because <function>flock</function> requires a file pointer, you may have Index: phpdoc/en/reference/filesystem/functions/fpassthru.xml diff -u phpdoc/en/reference/filesystem/functions/fpassthru.xml:1.5 phpdoc/en/reference/filesystem/functions/fpassthru.xml:1.6 --- phpdoc/en/reference/filesystem/functions/fpassthru.xml:1.5 Sun Jan 12 21:54:28 2003 +++ phpdoc/en/reference/filesystem/functions/fpassthru.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.fpassthru"> <refnamediv> @@ -50,6 +50,30 @@ your scripts will be more portable. </para> </note> + <para> + <example> + <title>Using <function>fpassthru</function> with binary files</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// open the file in a binary mode +$name = ".\public\dev\img\ok.png"; +$fp = fopen($name, 'rb'); + +// send the right headers +header("Content-Type: image/png"); +header("Content-Length: ".filesize($name)); + +// dump the picture and stop the script +fpassthru($fp); +exit; + +?> +]]> + </programlisting> + </example> + </para> <simpara> See also <function>readfile</function>, <function>fopen</function>, <function>popen</function>, and Index: phpdoc/en/reference/filesystem/functions/fseek.xml diff -u phpdoc/en/reference/filesystem/functions/fseek.xml:1.5 phpdoc/en/reference/filesystem/functions/fseek.xml:1.6 --- phpdoc/en/reference/filesystem/functions/fseek.xml:1.5 Sun Jan 26 21:50:41 2003 +++ phpdoc/en/reference/filesystem/functions/fseek.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.fseek"> <refnamediv> @@ -29,12 +29,34 @@ value in <parameter>offset</parameter>.)</member> </simplelist> </para> - <para>If <parameter>whence</parameter> is not specified, it is assumed to be - <constant>SEEK_SET</constant>. + <para> + If <parameter>whence</parameter> is not specified, it is assumed to be + <constant>SEEK_SET</constant>. </para> <para> Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error. + </para> + <para> + <example> + <title><function>fseek</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +$fp = fopen('somefile.txt'); + +// read some data +$data = fgets($fp, 4096); + +// move back to the begining of the file +// same as rewind($fp); +fseek($fp, 0); + +?> +]]> + </programlisting> + </example> </para> <para> May not be used on file pointers returned by Index: phpdoc/en/reference/filesystem/functions/fstat.xml diff -u phpdoc/en/reference/filesystem/functions/fstat.xml:1.7 phpdoc/en/reference/filesystem/functions/fstat.xml:1.8 --- phpdoc/en/reference/filesystem/functions/fstat.xml:1.7 Sat May 24 16:43:53 2003 +++ phpdoc/en/reference/filesystem/functions/fstat.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.7 $ --> +<!-- $Revision: 1.8 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.24 --> <refentry id="function.fstat"> <refnamediv> @@ -21,6 +21,53 @@ <para> Returns an array with the statistics of the file; the format of the array is described in detail on the <function>stat</function> manual page. + </para> + <para> + <example> + <title><function>fstat</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// open a file +$fp = fopen("/etc/passwd", "r"); + +// gather statistics +$fstat = fstat($fp); + +// close the file +fclose($fp); + +// print only the associative part +print_r(array_slice($fstat, 13)); + +?> +]]> + </programlisting> + <para> + this will output : + </para> + <screen> +<![CDATA[ +Array +( + [dev] => 771 + [ino] => 488704 + [mode] => 33188 + [nlink] => 1 + [uid] => 0 + [gid] => 0 + [rdev] => 0 + [size] => 1114 + [atime] => 1061067181 + [mtime] => 1056136526 + [ctime] => 1056136526 + [blksize] => 4096 + [blocks] => 8 +) +]]> + </screen> + </example> </para> &note.clearstatcache; Index: phpdoc/en/reference/filesystem/functions/ftell.xml diff -u phpdoc/en/reference/filesystem/functions/ftell.xml:1.5 phpdoc/en/reference/filesystem/functions/ftell.xml:1.6 --- phpdoc/en/reference/filesystem/functions/ftell.xml:1.5 Wed Jan 15 15:22:11 2003 +++ phpdoc/en/reference/filesystem/functions/ftell.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.ftell"> <refnamediv> @@ -24,6 +24,27 @@ The file pointer must be valid, and must point to a file successfully opened by <function>fopen</function> or <function>popen</function>. + </para> + <para> + <example> + <title><function>ftell</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// opens a file and read some data +$fp = fopen("/etc/passwd", "r"); +$data = fgets($fp, 12); + +// where are we ? +echo ftell($fp); // 11 + +fclose($fp); + +?> +]]> + </programlisting> + </example> </para> <para> See also <function>fopen</function>, <function>popen</function>, Index: phpdoc/en/reference/filesystem/functions/is-executable.xml diff -u phpdoc/en/reference/filesystem/functions/is-executable.xml:1.7 phpdoc/en/reference/filesystem/functions/is-executable.xml:1.8 --- phpdoc/en/reference/filesystem/functions/is-executable.xml:1.7 Mon May 19 20:10:05 2003 +++ phpdoc/en/reference/filesystem/functions/is-executable.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.7 $ --> +<!-- $Revision: 1.8 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.is-executable"> <refnamediv> @@ -18,6 +18,26 @@ <para> <function>is_executable</function> became available with Windows in PHP version 5.0.0. + </para> + <para> + <example> + <title><function>is_executable</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +$file = '/home/vincent/somefile.sh'; + +if(is_executable($file)) { + echo $file.' is executable'; +} else { + echo $file.' is not executable'; +} + +?> +]]> + </programlisting> + </example> </para> &note.clearstatcache; Index: phpdoc/en/reference/filesystem/functions/link.xml diff -u phpdoc/en/reference/filesystem/functions/link.xml:1.5 phpdoc/en/reference/filesystem/functions/link.xml:1.6 --- phpdoc/en/reference/filesystem/functions/link.xml:1.5 Thu Jun 12 21:40:03 2003 +++ phpdoc/en/reference/filesystem/functions/link.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.link"> <refnamediv> @@ -14,7 +14,7 @@ <methodparam><type>string</type><parameter>link</parameter></methodparam> </methodsynopsis> <para> - <function>link</function> creates a hard link. + <function>link</function> creates a hard link. &return.success; </para> &note.no-remote; Index: phpdoc/en/reference/filesystem/functions/linkinfo.xml diff -u phpdoc/en/reference/filesystem/functions/linkinfo.xml:1.3 phpdoc/en/reference/filesystem/functions/linkinfo.xml:1.4 --- phpdoc/en/reference/filesystem/functions/linkinfo.xml:1.3 Tue Aug 13 23:28:02 2002 +++ phpdoc/en/reference/filesystem/functions/linkinfo.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.linkinfo"> <refnamediv> @@ -19,6 +19,20 @@ <parameter>path</parameter>) really exists (using the same method as the S_ISLNK macro defined in stat.h). Returns 0 or &false; in case of error. + </para> + <para> + <example> + <title><function>linkinfo</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +echo linkinfo('/vmlinuz'); // 835 + +?> +]]> + </programlisting> + </example> </para> <para> See also <function>symlink</function>, <function>link</function>, Index: phpdoc/en/reference/filesystem/functions/readlink.xml diff -u phpdoc/en/reference/filesystem/functions/readlink.xml:1.3 phpdoc/en/reference/filesystem/functions/readlink.xml:1.4 --- phpdoc/en/reference/filesystem/functions/readlink.xml:1.3 Tue Aug 13 23:28:02 2002 +++ phpdoc/en/reference/filesystem/functions/readlink.xml Sat Aug 16 17:42:13 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.readlink"> <refnamediv> @@ -16,6 +16,21 @@ <function>readlink</function> does the same as the readlink C function and returns the contents of the symbolic link path or 0 in case of error. + </para> + <para> + <example> + <title><function>readlink</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// output e.g. /boot/vmlinux-2.4.20-xfs +echo readlink('/vmlinuz'); + +?> +]]> + </programlisting> + </example> </para> <para> See also <function>is_link</function>,
« previous php.doc (#969355853) next »