cvs: phpdoc-zh /reference/filesystem/functions file-register-wrapper.xml
| From: | Dallas Thunder | Date: | Thu, 26 Sep 2002 08:51:32 +0000 |
| Subject: | cvs: phpdoc-zh /reference/filesystem/functions file-register-wrapper.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-637@lists.php.net to get a copy of this message | ||
dallas Thu Sep 26 04:51:32 2002 EDT
Modified files:
/phpdoc-zh/reference/filesystem/functions file-register-wrapper.xml
Log:
Update.
Index: phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml diff -u phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.1 phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.2 --- phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.1 Thu Sep 26 03:51:00 2002 +++ phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml Thu Sep 26 04:51:32 2002 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: dallas $ --> -<!-- EN-Revision: 1.2 Maintainer: dallas Status: ready --> +<!-- EN-Revision: 1.5 Maintainer: dallas Status: ready --> <refentry id="function.file-register-wrapper"> <refnamediv> <refname>file_register_wrapper</refname> @@ -15,74 +15,261 @@ <methodparam><type>string</type><parameter>classname</parameter></methodparam> </methodsynopsis> <para> - ±¾º¯ÊýĿǰ½öͨ¹ýÒÔÏÂÀý×ÓÁÐÈëÎĵµ£º + <function>file_register_wrapper</function> + ÔÊÐíÓû§ÊµÏÖ×Ô¶¨ÒåµÄÐÒé´¦ÀíÆ÷ºÍÁ÷£¬ÓÃÓÚËùÓÐÆäËüµÄÎļþϵͳº¯ÊýÖУ¨ÀýÈç + <function>fopen</function>£¬<function>fread</function> µÈ£©¡£ + </para> + <para> + ҪʵÏÖÒ»¸ö·â×°ÐÒ飬ÐèÒª°´ÕÕÈç϶¨ÒåÉùÃ÷Ò»¸ö°üº¬ÓÐһЩº¯ÊýµÄÀà¡£µ±ÓÐÈ˶ÔÄãµÄÁ÷ʹÓà + fopen ʱ£¬PHP ½«´´½¨Ò»¸ö <parameter>classname</parameter> + µÄʵÀý²¢µ÷ÓøÃʵÀýµÄ·½·¨¡£±ØÐëÑϸñ°´ÕÕÈçϵÄÃèÊöʵÏÖ·½·¨ - ·ñÔò½«µ¼Ö²»Ã÷È·µÄÐÐΪ¡£ + </para> + <para> + Èç¹û <parameter>protocol</parameter> + ÒѾÓÐÁË´¦ÀíÐÒ飬Ôò <function>file_register_wrapper</function> + ½«·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_open</methodname> + <methodparam><type>string</type><parameter>path</parameter></methodparam> + <methodparam><type>string</type><parameter>mode</parameter></methodparam> + <methodparam><type>int</type><parameter>options</parameter></methodparam> + <methodparam><type>string</type><parameter>opened_path</parameter></methodparam> + </methodsynopsis> + <para> + µ±ÄãµÄÁ÷¶ÔÏó±»´´½¨Ö®ºóÁ¢¼´»áµ÷Óô˷½·¨¡£<parameter>path</parameter> + Ö¸¶¨ÁË´«Èë <function>fopen</function> ÒÔ¼°´Ë¶ÔÏóÐèҪȡ»ØµÄ URL¡£¿ÉÒÔÓà + <function>parse_url</function> À´½«´Ë URL ·Ö¸î³É¼¸²¿·Ö¡£ + </para> + <para> + <parameter>mode</parameter> ÓÃÀ´´ò¿ªÎļþµÄģʽ£¬ºÍ + <function>fopen</function> ÖеÄÒ»Ñù¡£ÄãÓÐÔðÈμì²é + <parameter>mode</parameter> ¶ÔÓÚËùÇëÇóµÄ + <parameter>path</parameter> ÊÇ·ñºÏ·¨¡£ + </para> + <para> + <parameter>options</parameter> ±£´æÁËͨ¹ýÁ÷ API + É趨µÄ¸½¼Ó±êÖ¾¡£¿ÉÒÔ±£´æÒÔÏÂÒ»¸öÖµ»òÕßÓà OR ºÏ²¢µÄ¶à¸öÖµ¡£ + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>±êÖ¾</entry> + <entry>˵Ã÷</entry> + </row> + </thead> + <tbody> + <row> + <entry>STREAM_USE_PATH</entry> + <entry>Èç¹û <parameter>path</parameter> ÊÇÏà¶Ô·¾¶£¬ÔòÓà + include_path ËÑË÷×ÊÔ´¡£ + </entry> + </row> + <row> + <entry>STREAM_REPORT_ERRORS</entry> + <entry>Èç¹ûÉ趨Á˱¾±êÖ¾£¬ÄãÓÐÔðÈÎÔÚ´ò¿ªÁ÷ʱÓà <function>trigger_error</function> + À´»½Æð´íÎó¡£Èç¹ûûÓÐÉ趨Õâ¸ö±êÖ¾£¬ÄÇôÄã²»ÐèÒª»½ÆðÈκδíÎó¡£ + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + <para> + Èç¹û³É¹¦´ò¿ªÁË <parameter>path</parameter>£¬²¢ÇÒÔÚ <parameter>options</parameter> + ÖÐÉ趨ÁË STREAM_USE_PATH£¬ÄãÐèÒª½« <parameter>opened_path</parameter> + É趨Ϊʵ¼Ê±»´ò¿ªµÄÎļþ£¯×ÊÔ´µÄÍêÕû·¾¶¡£ + </para> + <para> + Èç¹û³É¹¦´ò¿ªÁËËùÇëÇóµÄ×ÊÔ´£¬Ó¦¸Ã·µ»Ø + &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>void</type><methodname>stream_close</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + ±¾·½·¨ÔÚÁ÷¹Ø±Õʱ±»µ÷Óã¬Ê¹Óà + <function>fclose</function>¡£±ØÐëÊͷű»Á÷Ëø¶¨»ò·ÖÅäµÄÈκÎ×ÊÔ´¡£ + </para> + + <methodsynopsis> + <type>string</type><methodname>stream_read</methodname> + <methodparam><type>int</type><parameter>count</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fread</function> ºÍ <function>fgets</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷ÓᣱØÐë´Óµ±Ç°¶ÁдλÖÃÒÔ×Ö·û´®·µ»Ø×î¶à + <parameter>count</parameter> ×Ö½ÚµÄÊý¾Ý¡£Èç¹û¿ÉÓÃÊý¾ÝÉÙÓÚ <parameter>count</parameter> + ×Ö½Ú£¬Ôò·µ»Ø¾¡¿ÉÄܶàµÄÊý¾Ý¡£Èç¹ûûÓпɹ©·µ»ØµÄÊý¾Ý£¬·µ»Ø &false; + »òÕß¿Õ×Ö·û´®¡£±ØÐëÓóɹ¦¶ÁÈ¡µÄ×Ö½ÚÊýÈ¥¸üÐÂÁ÷µÄ¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>int</type><methodname>stream_write</methodname> + <methodparam><type>string</type><parameter>data</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fwrite</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷ÓᣱØÐ뽫 <parameter>data</parameter> + ´¢´æµ½ÄãµÄÁ÷ʹÓÃµÄµ×²ã´æ´¢¿Õ¼äÈ¥¡£Èç¹ûûÓÐ×ã¹»µÄ¿Õ¼äÁË£¬ÔòÊÔ×ű£´æ¾¡¿ÉÄܶàµÄ×Ö½Ú¡£Ó¦¸Ã·µ»Ø³É¹¦±»±£´æÈëÁ÷µÄ×Ö½ÚÊý£¬»òÕßûÓб£´æÊ±·µ»Ø + 0¡£±ØÐëÓóɹ¦Ð´ÈëµÄ×Ö½ÚÊýÈ¥¸üÐÂÁ÷µÄ¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_eof</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>feof</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Èç¹û¶ÁдλÖõ½ÁËÁ÷µÄ¾¡Í·»òÕßûÓиü¶àÊý¾Ý¿É¶Áʱ·µ»Ø + &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>int</type><methodname>stream_tell</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>ftell</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Ó¦¸Ã·µ»ØÁ÷µÄµ±Ç°¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_seek</methodname> + <methodparam><type>int</type><parameter>offset</parameter></methodparam> + <methodparam><type>int</type><parameter>whence</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fseek</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Ó¦¸Ã¸ù¾Ý <parameter>offset</parameter> ºÍ + <parameter>whence</parameter> À´¸üÐÂÁ÷µÄ¶ÁдλÖá£ÕâЩ²ÎÊýµÄ¸ü¶àÐÅÏ¢¼û + <function>fseek</function>¡£Èç¹ûλÖóɹ¦¸üÐÂÁËÔò·µ»Ø &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_flush</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fflush</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Èç¹ûÄãÔÚÁ÷Öлº´æÁËÊý¾Ý»¹Ã»ÓÐдÈëµ×²ã´æ´¢¿Õ¼äʱ£¬ÄÇÏÖÔÚÓ¦¸Ã×öÁË¡£Èç¹û»º´æÊý¾Ý±»³É¹¦±£´æ£¨»òûÓÐÊý¾Ý¿É¹©±£´æ£©Ê±·µ»Ø + &true;£¬µ±Êý¾ÝÎÞ·¨±»±£´æÊ±·µ»Ø &false;¡£ + </para> + + <para> + ÏÂÃæµÄÀý×ÓʵÏÖÁËÒ»¸ö var:// + ÐÒé´¦ÀíÆ÷£¬¿ÉÒÔÔÊÐíʹÓñê×¼µÄÎļþϵͳÁ÷º¯ÊýÀ´¶ÔÖ¸¶¨µÄÈ«¾Ö±äÁ¿½øÐжÁд²Ù×÷£¬ÀýÈç + <function>fread</function>¡£var:// ÐÒéµÄʵÏÖÈçÏ£¬¸ø³ö + url "var://foo" ½«¿ÉÒÔ¶Áд $GLOBALS["foo"]¡£ + <example> - <title>ʵÏÖÒ»¸ö base64 ±àÂëÐÒé</title> + <title>¶Áдȫ¾Ö±äÁ¿µÄÁ÷</title> <programlisting role="php"> <![CDATA[ -class Base64EncodingStream { - var $fp = null; - +class VariableStream { + var $position; + var $varname; + function stream_open($path, $mode, $options, &$opened_path) { - $this->fp = fopen($path, $mode); - return is_resource($this->fp); - } - function stream_close() - { - fclose($this->fp); + $url = parse_url($path); + $this->varname = $url["host"]; + $this->position = 0; + + return true; } + function stream_read($count) { - return false; // We only allow writing + $ret = substr($GLOBALS[$this->varname], $this->position, $count); + $this->position += strlen($ret); + return $ret; } + function stream_write($data) { - return fwrite($this->fp, base64_encode($data)); - } - function stream_flush() - { - fflush($this->fp); - return true; - } - function stream_seek($offset, $whence) - { - return false; - } - function stream_gets() - { - return false; + $left = substr($GLOBALS[$this->varname], 0, $this->position); + $right = substr($GLOBALS[$this->varname], $this->position + strlen($data)); + $GLOBALS[$this->varname] = $left . $data . $right; + $this->position += strlen($data); + return strlen($data); } + function stream_tell() { - return false; + return $this->position; } + function stream_eof() { - return false; + return $this->position >= strlen($GLOBALS[$this->varname]); + } + + function stream_seek($offset, $whence) + { + switch($whence) { + case SEEK_SET: + if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { + $this->position = $offset; + return true; + } else { + return false; + } + break; + + case SEEK_CUR: + if ($offset >= 0) { + $this->position += $offset; + return true; + } else { + return false; + } + break; + + case SEEK_END: + if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { + $this->position = strlen($GLOBALS[$this->varname]) + $offset; + return true; + } else { + return false; + } + break; + + default: + return false; + } } } -file_register_wrapper("base64", "Base64EncodingStream") + +file_register_wrapper("var", "VariableStream") or die("Failed to register protocol"); -copy("/tmp/inputfile.txt", "base64:///tmp/outputfile.txt"); -readfile("/tmp/outputfile"); +$myvar = ""; + +$fp = fopen("var://myvar", "r+"); + +fwrite($fp, "line1\n"); +fwrite($fp, "line2\n"); +fwrite($fp, "line3\n"); + +rewind($fp); +while(!feof($fp)) { + echo fgets($fp) +} +fclose($fp); +var_dump($myvar); + ]]> </programlisting> </example> - </para> - <para> - Èç¹û <parameter>protocol</parameter> ÒѾÓÐÁ˾ä±ú£¬»òÕß¡°fopen wrappers¡±Ã»Óб»¼¤»îʱ - <function>file_register_wrapper</function> ·µ»Ø &false;¡£ - </para> - <note> - <para> - ±¾º¯ÊýÊÇ PHP 4.3.0 Òý½øµÄ¡£ - </para> - </note> + </refsect1> </refentry> + <!-- Keep this comment at the end of the file Local variables:
Index: phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml diff -u phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.1 phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.2 --- phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml:1.1 Thu Sep 26 03:51:00 2002 +++ phpdoc-zh/reference/filesystem/functions/file-register-wrapper.xml Thu Sep 26 04:51:32 2002 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: dallas $ --> -<!-- EN-Revision: 1.2 Maintainer: dallas Status: ready --> +<!-- EN-Revision: 1.5 Maintainer: dallas Status: ready --> <refentry id="function.file-register-wrapper"> <refnamediv> <refname>file_register_wrapper</refname> @@ -15,74 +15,261 @@ <methodparam><type>string</type><parameter>classname</parameter></methodparam> </methodsynopsis> <para> - ±¾º¯ÊýĿǰ½öͨ¹ýÒÔÏÂÀý×ÓÁÐÈëÎĵµ£º + <function>file_register_wrapper</function> + ÔÊÐíÓû§ÊµÏÖ×Ô¶¨ÒåµÄÐÒé´¦ÀíÆ÷ºÍÁ÷£¬ÓÃÓÚËùÓÐÆäËüµÄÎļþϵͳº¯ÊýÖУ¨ÀýÈç + <function>fopen</function>£¬<function>fread</function> µÈ£©¡£ + </para> + <para> + ҪʵÏÖÒ»¸ö·â×°ÐÒ飬ÐèÒª°´ÕÕÈç϶¨ÒåÉùÃ÷Ò»¸ö°üº¬ÓÐһЩº¯ÊýµÄÀà¡£µ±ÓÐÈ˶ÔÄãµÄÁ÷ʹÓà + fopen ʱ£¬PHP ½«´´½¨Ò»¸ö <parameter>classname</parameter> + µÄʵÀý²¢µ÷ÓøÃʵÀýµÄ·½·¨¡£±ØÐëÑϸñ°´ÕÕÈçϵÄÃèÊöʵÏÖ·½·¨ - ·ñÔò½«µ¼Ö²»Ã÷È·µÄÐÐΪ¡£ + </para> + <para> + Èç¹û <parameter>protocol</parameter> + ÒѾÓÐÁË´¦ÀíÐÒ飬Ôò <function>file_register_wrapper</function> + ½«·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_open</methodname> + <methodparam><type>string</type><parameter>path</parameter></methodparam> + <methodparam><type>string</type><parameter>mode</parameter></methodparam> + <methodparam><type>int</type><parameter>options</parameter></methodparam> + <methodparam><type>string</type><parameter>opened_path</parameter></methodparam> + </methodsynopsis> + <para> + µ±ÄãµÄÁ÷¶ÔÏó±»´´½¨Ö®ºóÁ¢¼´»áµ÷Óô˷½·¨¡£<parameter>path</parameter> + Ö¸¶¨ÁË´«Èë <function>fopen</function> ÒÔ¼°´Ë¶ÔÏóÐèҪȡ»ØµÄ URL¡£¿ÉÒÔÓà + <function>parse_url</function> À´½«´Ë URL ·Ö¸î³É¼¸²¿·Ö¡£ + </para> + <para> + <parameter>mode</parameter> ÓÃÀ´´ò¿ªÎļþµÄģʽ£¬ºÍ + <function>fopen</function> ÖеÄÒ»Ñù¡£ÄãÓÐÔðÈμì²é + <parameter>mode</parameter> ¶ÔÓÚËùÇëÇóµÄ + <parameter>path</parameter> ÊÇ·ñºÏ·¨¡£ + </para> + <para> + <parameter>options</parameter> ±£´æÁËͨ¹ýÁ÷ API + É趨µÄ¸½¼Ó±êÖ¾¡£¿ÉÒÔ±£´æÒÔÏÂÒ»¸öÖµ»òÕßÓà OR ºÏ²¢µÄ¶à¸öÖµ¡£ + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>±êÖ¾</entry> + <entry>˵Ã÷</entry> + </row> + </thead> + <tbody> + <row> + <entry>STREAM_USE_PATH</entry> + <entry>Èç¹û <parameter>path</parameter> ÊÇÏà¶Ô·¾¶£¬ÔòÓà + include_path ËÑË÷×ÊÔ´¡£ + </entry> + </row> + <row> + <entry>STREAM_REPORT_ERRORS</entry> + <entry>Èç¹ûÉ趨Á˱¾±êÖ¾£¬ÄãÓÐÔðÈÎÔÚ´ò¿ªÁ÷ʱÓà <function>trigger_error</function> + À´»½Æð´íÎó¡£Èç¹ûûÓÐÉ趨Õâ¸ö±êÖ¾£¬ÄÇôÄã²»ÐèÒª»½ÆðÈκδíÎó¡£ + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + <para> + Èç¹û³É¹¦´ò¿ªÁË <parameter>path</parameter>£¬²¢ÇÒÔÚ <parameter>options</parameter> + ÖÐÉ趨ÁË STREAM_USE_PATH£¬ÄãÐèÒª½« <parameter>opened_path</parameter> + É趨Ϊʵ¼Ê±»´ò¿ªµÄÎļþ£¯×ÊÔ´µÄÍêÕû·¾¶¡£ + </para> + <para> + Èç¹û³É¹¦´ò¿ªÁËËùÇëÇóµÄ×ÊÔ´£¬Ó¦¸Ã·µ»Ø + &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>void</type><methodname>stream_close</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + ±¾·½·¨ÔÚÁ÷¹Ø±Õʱ±»µ÷Óã¬Ê¹Óà + <function>fclose</function>¡£±ØÐëÊͷű»Á÷Ëø¶¨»ò·ÖÅäµÄÈκÎ×ÊÔ´¡£ + </para> + + <methodsynopsis> + <type>string</type><methodname>stream_read</methodname> + <methodparam><type>int</type><parameter>count</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fread</function> ºÍ <function>fgets</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷ÓᣱØÐë´Óµ±Ç°¶ÁдλÖÃÒÔ×Ö·û´®·µ»Ø×î¶à + <parameter>count</parameter> ×Ö½ÚµÄÊý¾Ý¡£Èç¹û¿ÉÓÃÊý¾ÝÉÙÓÚ <parameter>count</parameter> + ×Ö½Ú£¬Ôò·µ»Ø¾¡¿ÉÄܶàµÄÊý¾Ý¡£Èç¹ûûÓпɹ©·µ»ØµÄÊý¾Ý£¬·µ»Ø &false; + »òÕß¿Õ×Ö·û´®¡£±ØÐëÓóɹ¦¶ÁÈ¡µÄ×Ö½ÚÊýÈ¥¸üÐÂÁ÷µÄ¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>int</type><methodname>stream_write</methodname> + <methodparam><type>string</type><parameter>data</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fwrite</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷ÓᣱØÐ뽫 <parameter>data</parameter> + ´¢´æµ½ÄãµÄÁ÷ʹÓÃµÄµ×²ã´æ´¢¿Õ¼äÈ¥¡£Èç¹ûûÓÐ×ã¹»µÄ¿Õ¼äÁË£¬ÔòÊÔ×ű£´æ¾¡¿ÉÄܶàµÄ×Ö½Ú¡£Ó¦¸Ã·µ»Ø³É¹¦±»±£´æÈëÁ÷µÄ×Ö½ÚÊý£¬»òÕßûÓб£´æÊ±·µ»Ø + 0¡£±ØÐëÓóɹ¦Ð´ÈëµÄ×Ö½ÚÊýÈ¥¸üÐÂÁ÷µÄ¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_eof</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>feof</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Èç¹û¶ÁдλÖõ½ÁËÁ÷µÄ¾¡Í·»òÕßûÓиü¶àÊý¾Ý¿É¶Áʱ·µ»Ø + &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>int</type><methodname>stream_tell</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>ftell</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Ó¦¸Ã·µ»ØÁ÷µÄµ±Ç°¶ÁдλÖᣠ+ </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_seek</methodname> + <methodparam><type>int</type><parameter>offset</parameter></methodparam> + <methodparam><type>int</type><parameter>whence</parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fseek</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Ó¦¸Ã¸ù¾Ý <parameter>offset</parameter> ºÍ + <parameter>whence</parameter> À´¸üÐÂÁ÷µÄ¶ÁдλÖá£ÕâЩ²ÎÊýµÄ¸ü¶àÐÅÏ¢¼û + <function>fseek</function>¡£Èç¹ûλÖóɹ¦¸üÐÂÁËÔò·µ»Ø &true;£¬·ñÔò·µ»Ø &false;¡£ + </para> + + <methodsynopsis> + <type>boolean</type><methodname>stream_flush</methodname> + <methodparam><type>void</type><parameter></parameter></methodparam> + </methodsynopsis> + <para> + µ±¶ÔÁ÷½øÐÐ <function>fflush</function> + ²Ù×÷ʱ±¾·½·¨±»µ÷Óá£Èç¹ûÄãÔÚÁ÷Öлº´æÁËÊý¾Ý»¹Ã»ÓÐдÈëµ×²ã´æ´¢¿Õ¼äʱ£¬ÄÇÏÖÔÚÓ¦¸Ã×öÁË¡£Èç¹û»º´æÊý¾Ý±»³É¹¦±£´æ£¨»òûÓÐÊý¾Ý¿É¹©±£´æ£©Ê±·µ»Ø + &true;£¬µ±Êý¾ÝÎÞ·¨±»±£´æÊ±·µ»Ø &false;¡£ + </para> + + <para> + ÏÂÃæµÄÀý×ÓʵÏÖÁËÒ»¸ö var:// + ÐÒé´¦ÀíÆ÷£¬¿ÉÒÔÔÊÐíʹÓñê×¼µÄÎļþϵͳÁ÷º¯ÊýÀ´¶ÔÖ¸¶¨µÄÈ«¾Ö±äÁ¿½øÐжÁд²Ù×÷£¬ÀýÈç + <function>fread</function>¡£var:// ÐÒéµÄʵÏÖÈçÏ£¬¸ø³ö + url "var://foo" ½«¿ÉÒÔ¶Áд $GLOBALS["foo"]¡£ + <example> - <title>ʵÏÖÒ»¸ö base64 ±àÂëÐÒé</title> + <title>¶Áдȫ¾Ö±äÁ¿µÄÁ÷</title> <programlisting role="php"> <![CDATA[ -class Base64EncodingStream { - var $fp = null; - +class VariableStream { + var $position; + var $varname; + function stream_open($path, $mode, $options, &$opened_path) { - $this->fp = fopen($path, $mode); - return is_resource($this->fp); - } - function stream_close() - { - fclose($this->fp); + $url = parse_url($path); + $this->varname = $url["host"]; + $this->position = 0; + + return true; } + function stream_read($count) { - return false; // We only allow writing + $ret = substr($GLOBALS[$this->varname], $this->position, $count); + $this->position += strlen($ret); + return $ret; } + function stream_write($data) { - return fwrite($this->fp, base64_encode($data)); - } - function stream_flush() - { - fflush($this->fp); - return true; - } - function stream_seek($offset, $whence) - { - return false; - } - function stream_gets() - { - return false; + $left = substr($GLOBALS[$this->varname], 0, $this->position); + $right = substr($GLOBALS[$this->varname], $this->position + strlen($data)); + $GLOBALS[$this->varname] = $left . $data . $right; + $this->position += strlen($data); + return strlen($data); } + function stream_tell() { - return false; + return $this->position; } + function stream_eof() { - return false; + return $this->position >= strlen($GLOBALS[$this->varname]); + } + + function stream_seek($offset, $whence) + { + switch($whence) { + case SEEK_SET: + if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { + $this->position = $offset; + return true; + } else { + return false; + } + break; + + case SEEK_CUR: + if ($offset >= 0) { + $this->position += $offset; + return true; + } else { + return false; + } + break; + + case SEEK_END: + if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { + $this->position = strlen($GLOBALS[$this->varname]) + $offset; + return true; + } else { + return false; + } + break; + + default: + return false; + } } } -file_register_wrapper("base64", "Base64EncodingStream") + +file_register_wrapper("var", "VariableStream") or die("Failed to register protocol"); -copy("/tmp/inputfile.txt", "base64:///tmp/outputfile.txt"); -readfile("/tmp/outputfile"); +$myvar = ""; + +$fp = fopen("var://myvar", "r+"); + +fwrite($fp, "line1\n"); +fwrite($fp, "line2\n"); +fwrite($fp, "line3\n"); + +rewind($fp); +while(!feof($fp)) { + echo fgets($fp) +} +fclose($fp); +var_dump($myvar); + ]]> </programlisting> </example> - </para> - <para> - Èç¹û <parameter>protocol</parameter> ÒѾÓÐÁ˾ä±ú£¬»òÕß¡°fopen wrappers¡±Ã»Óб»¼¤»îʱ - <function>file_register_wrapper</function> ·µ»Ø &false;¡£ - </para> - <note> - <para> - ±¾º¯ÊýÊÇ PHP 4.3.0 Òý½øµÄ¡£ - </para> - </note> + </refsect1> </refentry> + <!-- Keep this comment at the end of the file Local variables: