<!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 NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="List of Supported Protocols/Wrappers" HREF="wrappers.html"><LINK REL="PREVIOUS" TITLE="FTP and FTPS" HREF="wrappers.ftp.html"><LINK REL="NEXT" TITLE="Compression Streams" HREF="wrappers.compression.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="section" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="wrappers.ftp.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Apêndice N. List of Supported Protocols/Wrappers</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="wrappers.compression.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wrappers.php" >PHP input/output streams</A ></H1 ><P ></P ><UL ><LI ><P ><TT CLASS="filename" >php://stdin</TT ></P ></LI ><LI ><P ><TT CLASS="filename" >php://stdout</TT ></P ></LI ><LI ><P ><TT CLASS="filename" >php://stderr</TT ></P ></LI ><LI ><P ><TT CLASS="filename" >php://output</TT ></P ></LI ><LI ><P ><TT CLASS="filename" >php://input</TT ></P ></LI ><LI ><P ><TT CLASS="filename" >php://filter</TT > (available since PHP 5.0.0)</P ></LI ><LI ><P ><TT CLASS="filename" >php://memory</TT > (available since PHP 5.1.0)</P ></LI ><LI ><P ><TT CLASS="filename" >php://temp</TT > (available since PHP 5.1.0)</P ></LI ></UL ><P > <TT CLASS="filename" >php://stdin</TT >, <TT CLASS="filename" >php://stdout</TT > and <TT CLASS="filename" >php://stderr</TT > allow access to the corresponding input or output stream of the PHP process. The stream references a duplicate file descriptor, so if you open <TT CLASS="filename" >php://stdin</TT > and later close it, you close only your copy of the descriptor--the actual stream referenced by <TT CLASS="constant" ><B >STDIN</B ></TT > 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 <TT CLASS="constant" ><B >STDIN</B ></TT >, <TT CLASS="constant" ><B >STDOUT</B ></TT > and <TT CLASS="constant" ><B >STDERR</B ></TT > instead of manually opening streams using these wrappers. </P ><P > <TT CLASS="filename" >php://output</TT > allows you to write to the output buffer mechanism in the same way as <A HREF="function.print.html" ><B CLASS="function" >print()</B ></A > and <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A >. </P ><P > <TT CLASS="filename" >php://input</TT > allows you to read raw POST data. It is a less memory intensive alternative to <CODE CLASS="varname" >$HTTP_RAW_POST_DATA</CODE > and does not need any special <TT CLASS="filename" >php.ini</TT > directives. <TT CLASS="filename" >php://input</TT > is not available with <TT CLASS="literal" >enctype="multipart/form-data"</TT >. </P ><P > <TT CLASS="filename" >php://stdin</TT > and <TT CLASS="filename" >php://input</TT > are read-only, whereas <TT CLASS="filename" >php://stdout</TT >, <TT CLASS="filename" >php://stderr</TT > and <TT CLASS="filename" >php://output</TT > are write-only. </P ><P > <TT CLASS="filename" >php://filter</TT > 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" ><B CLASS="function" >readfile()</B ></A >, <A HREF="function.file.html" ><B CLASS="function" >file()</B ></A >, and <A HREF="function.file-get-contents.html" ><B CLASS="function" >file_get_contents()</B ></A > where there is otherwise no opportunity to apply a filter to the stream prior the contents being read. </P ><P > The <TT CLASS="filename" >php://filter</TT > target takes the following 'parameters' as parts of its 'path'. </P ><P ></P ><UL ><LI ><P > <TT CLASS="literal" >/resource=<stream to be filtered></TT > (<SPAN CLASS="emphasis" ><I CLASS="emphasis" >required</I ></SPAN >) This parameter must be located at the end of your <TT CLASS="filename" >php://filter</TT > specification and should point to the stream which you want filtered. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN288674" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* This is equivalent to simply:<br /> readfile("http://www.example.com");<br /> since no filters are actually specified */<br /><br /></font><font color="#0000BB">readfile</font><font color="#007700">(</font><font color="#DD0000">"php://filter/resource=http://www.example.com"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ><LI ><P > <TT CLASS="literal" >/read=<filter list to apply to read chain></TT > (<SPAN CLASS="emphasis" ><I CLASS="emphasis" >optional</I ></SPAN >) This parameter takes one or more filternames separated by the pipe character <TT CLASS="literal" >|</TT >. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN288681" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* This will output the contents of <br /> www.example.com entirely in uppercase */<br /></font><font color="#0000BB">readfile</font><font color="#007700">(</font><font color="#DD0000">"php://filter/read=string.toupper/resource=http://www.example.com"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* This will do the same as above<br /> but will also ROT13 encode it */<br /></font><font color="#0000BB">readfile</font><font color="#007700">(</font><font color="#DD0000">"php://filter/read=string.toupper|string.rot13/resource=http://www.example.com"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ><LI ><P > <TT CLASS="literal" >/write=<filter list to apply to write chain></TT > (<SPAN CLASS="emphasis" ><I CLASS="emphasis" >optional</I ></SPAN >) This parameter takes one or more filternames separated by the pipe character <TT CLASS="literal" >|</TT >. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN288688" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* This will filter the string "Hello World"<br /> through the rot13 filter, then write to<br /> example.txt in the current directory */<br /></font><font color="#0000BB">file_put_contents</font><font color="#007700">(</font><font color="#DD0000">"php://filter/write=string.rot13/resource=example.txt"</font><font color="#007700">,</font><font color="#DD0000">"Hello World"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ><LI ><P > <TT CLASS="literal" >/<filter list to apply to both chains></TT > (<SPAN CLASS="emphasis" ><I CLASS="emphasis" >optional</I ></SPAN >) Any filter lists which are not prefixed specifically by <TT CLASS="literal" >read=</TT > or <TT CLASS="literal" >write=</TT > will be applied to both the read and write chains (as appropriate). </P ></LI ></UL ><P > The <TT CLASS="filename" >php://memory</TT > wrapper stores the data in the memory. <TT CLASS="filename" >php://temp</TT > 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 > The <TT CLASS="filename" >php://temp</TT > wrapper takes the following 'parameters' as parts of its 'path': </P ><P ></P ><UL ><LI ><P > <TT CLASS="literal" >/maxmemory:<number of bytes></TT > (<SPAN CLASS="emphasis" ><I CLASS="emphasis" >optional</I ></SPAN >). This parameter allows changing the default value for the memory limit (when the data is moved to a temporary file). <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN288706" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$fiveMBs </font><font color="#007700">= </font><font color="#0000BB">5 </font><font color="#007700">* </font><font color="#0000BB">1024 </font><font color="#007700">* </font><font color="#0000BB">1024</font><font color="#007700">;<br /></font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#DD0000">"php://temp/maxmemory:$fiveMBs"</font><font color="#007700">, </font><font color="#DD0000">'r+'</font><font color="#007700">);<br /><br /></font><font color="#0000BB">fputs</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"hello\n"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// read what we have written<br /></font><font color="#0000BB">rewind</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br />echo </font><font color="#0000BB">stream_get_contents</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ></UL ><P > <DIV CLASS="table" ><A NAME="AEN288709" ></A ><P ><B >Tabela N-6. Wrapper Summary (For <TT CLASS="literal" >php://filter</TT >, refer to summary of wrapper being filtered.) </B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Attribute</TH ><TH >Supported</TH ></TR ></THEAD ><TBODY ><TR ><TD >Restricted by <A HREF="ref.filesystem.html#ini.allow-url-fopen" >allow_url_fopen</A ></TD ><TD >No</TD ></TR ><TR ><TD >Restricted by <A HREF="ref.filesystem.html#ini.allow-url-include" >allow_url_include</A ></TD ><TD > <TT CLASS="literal" >php://input</TT >, <TT CLASS="literal" >php://stdin</TT >, <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. </TD ></TR ><TR ><TD >Allows Reading</TD ><TD > <TT CLASS="literal" >php://stdin</TT >, <TT CLASS="literal" >php://input</TT >, <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. </TD ></TR ><TR ><TD >Allows Writing</TD ><TD > <TT CLASS="literal" >php://stdout</TT >, <TT CLASS="literal" >php://stderr</TT >, <TT CLASS="literal" >php://output</TT >, <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. </TD ></TR ><TR ><TD >Allows Appending</TD ><TD > <TT CLASS="literal" >php://stdout</TT >, <TT CLASS="literal" >php://stderr</TT >, <TT CLASS="literal" >php://output</TT >, <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. (Equivalent to writing) </TD ></TR ><TR ><TD >Allows Simultaneous Reading and Writing</TD ><TD > <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. </TD ></TR ><TR ><TD >Supports <A HREF="function.stat.html" ><B CLASS="function" >stat()</B ></A ></TD ><TD > <TT CLASS="literal" >php://memory</TT > and <TT CLASS="literal" >php://temp</TT > only. </TD ></TR ><TR ><TD >Supports <A HREF="function.unlink.html" ><B CLASS="function" >unlink()</B ></A ></TD ><TD >No</TD ></TR ><TR ><TD >Supports <A HREF="function.rename.html" ><B CLASS="function" >rename()</B ></A ></TD ><TD >No</TD ></TR ><TR ><TD >Supports <A HREF="function.mkdir.html" ><B CLASS="function" >mkdir()</B ></A ></TD ><TD >No</TD ></TR ><TR ><TD >Supports <A HREF="function.rmdir.html" ><B CLASS="function" >rmdir()</B ></A ></TD ><TD >No</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="wrappers.ftp.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="wrappers.compression.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >FTP and FTPS</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="wrappers.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Compression Streams</TD ></TR ></TABLE ></DIV ></BODY ></HTML >