wrappers.php.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 276 行

HTML
276
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>PHP input/output streams</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="wrappers.ftp.html">FTP and FTPS</a></div> <div class="next" style="text-align: right; float: right;"><a href="wrappers.compression.html">Compression Streams</a></div> <div class="up"><a href="wrappers.html">List of Supported Protocols/Wrappers</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="wrappers.php" class="section">  <h2 class="title">PHP input/output streams</h2>  <ul class="itemizedlist">   <li class="listitem"><span class="simpara"><var class="filename">php://stdin</var></span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://stdout</var></span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://stderr</var></span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://output</var></span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://input</var></span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://filter</var> (available since PHP 5.0.0)</span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://memory</var> (available since PHP 5.1.0)</span></li>   <li class="listitem"><span class="simpara"><var class="filename">php://temp</var> (available since PHP 5.1.0)</span></li>  </ul>  <p class="simpara">   <var class="filename">php://stdin</var>, <var class="filename">php://stdout</var>   and <var class="filename">php://stderr</var> allow access to   the corresponding input or output stream of the PHP process.  The stream   references a duplicate file descriptor, so if you open   <var class="filename">php://stdin</var> and later close it, you close only your   copy of the descriptor--the actual stream referenced by   <b><tt>STDIN</tt></b> is unaffected.  Note that PHP exhibited buggy   behavior in this regard until PHP 5.2.1.  It is recommended that you simply   use the constants <b><tt>STDIN</tt></b>, <b><tt>STDOUT</tt></b>   and <b><tt>STDERR</tt></b> instead of manually opening streams using   these wrappers.  </p>  <p class="simpara">   <var class="filename">php://output</var> allows you to write to the   output buffer mechanism in the same way as   <a href="function.print.html" class="function">print()</a> and <a href="function.echo.html" class="function">echo()</a>.  </p>  <p class="simpara">   <var class="filename">php://input</var> allows you to read raw POST data.   It is a less memory intensive alternative to   <var class="varname"><a href="reserved.variables.httprawpostdata.html" class="classname">$HTTP_RAW_POST_DATA</a></var> and does not need any   special <var class="filename">php.ini</var> directives.   <var class="filename">php://input</var> is not available with   <i>enctype=&quot;multipart/form-data&quot;</i>.  </p>  <p class="simpara">   <var class="filename">php://stdin</var> and   <var class="filename">php://input</var> are read-only, whereas   <var class="filename">php://stdout</var>,   <var class="filename">php://stderr</var> and   <var class="filename">php://output</var> are write-only.  </p>  <p class="simpara">   <var class="filename">php://filter</var> is a kind of meta-wrapper designed   to permit the application of filters to a stream at the time of   opening.  This is useful with all-in-one file functions such as   <a href="function.readfile.html" class="function">readfile()</a>, <a href="function.file.html" class="function">file()</a>, and   <a href="function.file-get-contents.html" class="function">file_get_contents()</a> where there is otherwise   no opportunity to apply a filter to the stream prior the contents   being read.  </p>  <p class="simpara">   The <var class="filename">php://filter</var> target takes the following   &#039;parameters&#039; as parts of its &#039;path&#039;.  </p>  <ul class="itemizedlist">   <li class="listitem">    <p class="para">     <i>/resource=&lt;stream to be filtered&gt;</i>     (<em class="emphasis">required</em>)  This parameter must be located at     the end of your <var class="filename">php://filter</var> specification and     should point to the stream which you want filtered.     <div class="informalexample">      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;is&nbsp;equivalent&nbsp;to&nbsp;simply:<br />&nbsp;&nbsp;&nbsp;readfile("http://www.example.com");<br />&nbsp;&nbsp;&nbsp;since&nbsp;no&nbsp;filters&nbsp;are&nbsp;actually&nbsp;specified&nbsp;*/<br /><br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/resource=http://www.example.com"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </div>    </p>   </li>   <li class="listitem">    <p class="para">     <i>/read=&lt;filter list to apply to read chain&gt;</i>     (<em class="emphasis">optional</em>)  This parameter takes one or more     filternames separated by the pipe character <i>|</i>.     <div class="informalexample">      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;output&nbsp;the&nbsp;contents&nbsp;of<br />&nbsp;&nbsp;&nbsp;www.example.com&nbsp;entirely&nbsp;in&nbsp;uppercase&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/read=string.toupper/resource=http://www.example.com"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;do&nbsp;the&nbsp;same&nbsp;as&nbsp;above<br />&nbsp;&nbsp;&nbsp;but&nbsp;will&nbsp;also&nbsp;ROT13&nbsp;encode&nbsp;it&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/read=string.toupper|string.rot13/resource=http://www.example.com"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </div>    </p>   </li>   <li class="listitem">    <p class="para">     <i>/write=&lt;filter list to apply to write chain&gt;</i>     (<em class="emphasis">optional</em>)  This parameter takes one or more     filternames separated by the pipe character <i>|</i>.     <div class="informalexample">      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;filter&nbsp;the&nbsp;string&nbsp;"Hello&nbsp;World"<br />&nbsp;&nbsp;&nbsp;through&nbsp;the&nbsp;rot13&nbsp;filter,&nbsp;then&nbsp;write&nbsp;to<br />&nbsp;&nbsp;&nbsp;example.txt&nbsp;in&nbsp;the&nbsp;current&nbsp;directory&nbsp;*/<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/write=string.rot13/resource=example.txt"</span><span style="color: #007700">,</span><span style="color: #DD0000">"Hello&nbsp;World"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </div>    </p>   </li>   <li class="listitem">    <span class="simpara">     <i>/&lt;filter list to apply to both chains&gt;</i>     (<em class="emphasis">optional</em>)  Any filter lists which are not     prefixed specifically by <i>read=</i> or     <i>write=</i> will be applied to both the read and     write chains (as appropriate).    </span>   </li>  </ul>  <p class="simpara">   The <var class="filename">php://memory</var> wrapper stores the data in the   memory. <var class="filename">php://temp</var> behaves similarly, but uses a   temporary file for storing the data when a certain memory limit is reached   (the default is 2 MB).  </p>  <p class="simpara">   The <var class="filename">php://temp</var> wrapper takes the following   &#039;parameters&#039; as parts of its &#039;path&#039;:  </p>  <ul class="itemizedlist">   <li class="listitem">    <p class="para">     <i>/maxmemory:&lt;number of bytes&gt;</i>     (<em class="emphasis">optional</em>). This parameter allows changing the     default value for the memory limit (when the data is moved to a temporary     file).     <div class="informalexample">      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fiveMBs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">5&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://temp/maxmemory:$fiveMBs"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r+'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">fputs</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"hello\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;read&nbsp;what&nbsp;we&nbsp;have&nbsp;written<br /></span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </div>    </p>   </li>  </ul>  <p class="para">   <table border="5">    <caption><b>     Wrapper Summary (For <i>php://filter</i>,     refer to summary of wrapper being filtered.)    </b></caption>    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Attribute</th>       <th colspan="1">Supported</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Restricted by <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">allow_url_fopen</a></td>       <td colspan="1" rowspan="1" align="left">No</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Restricted by <a href="filesystem.configuration.html#ini.allow-url-include" class="link">allow_url_include</a></td>       <td colspan="1" rowspan="1" align="left">        <i>php://input</i>,        <i>php://stdin</i>,        <i>php://memory</i> and        <i>php://temp</i> only.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Allows Reading</td>       <td colspan="1" rowspan="1" align="left">        <i>php://stdin</i>,        <i>php://input</i>,        <i>php://memory</i> and        <i>php://temp</i> only.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Allows Writing</td>       <td colspan="1" rowspan="1" align="left">        <i>php://stdout</i>,        <i>php://stderr</i>,        <i>php://output</i>,        <i>php://memory</i> and        <i>php://temp</i> only.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Allows Appending</td>       <td colspan="1" rowspan="1" align="left">        <i>php://stdout</i>,        <i>php://stderr</i>,        <i>php://output</i>,        <i>php://memory</i> and        <i>php://temp</i> only. (Equivalent to writing)       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Allows Simultaneous Reading and Writing</td>       <td colspan="1" rowspan="1" align="left">        <i>php://memory</i> and        <i>php://temp</i> only.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Supports <a href="function.stat.html" class="function">stat()</a></td>       <td colspan="1" rowspan="1" align="left">        <i>php://memory</i> and        <i>php://temp</i> only.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Supports <a href="function.unlink.html" class="function">unlink()</a></td>       <td colspan="1" rowspan="1" align="left">No</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Supports <a href="function.rename.html" class="function">rename()</a></td>       <td colspan="1" rowspan="1" align="left">No</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Supports <a href="function.mkdir.html" class="function">mkdir()</a></td>       <td colspan="1" rowspan="1" align="left">No</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Supports <a href="function.rmdir.html" class="function">rmdir()</a></td>       <td colspan="1" rowspan="1" align="left">No</td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="wrappers.ftp.html">FTP and FTPS</a></div> <div class="next" style="text-align: right; float: right;"><a href="wrappers.compression.html">Compression Streams</a></div> <div class="up"><a href="wrappers.html">List of Supported Protocols/Wrappers</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?