-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathphp.xml
397 lines (381 loc) · 12.7 KB
/
php.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="wrappers.php" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="verify_info:false" role="stream_wrapper">
<refnamediv>
<refname>php://</refname>
<refpurpose>Accessing various I/O streams</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>
PHP provides a number of miscellaneous I/O streams that allow access to
PHP's own input and output streams, the standard input, output and error
file descriptors, in-memory and disk-backed temporary file streams, and
filters that can manipulate other file resources as they are read from and
written to.
</para>
<refsect2 xml:id="wrappers.php.std">
<title>php://stdin, php://stdout and php://stderr</title>
<simpara>
<filename>php://stdin</filename>, <filename>php://stdout</filename> and
<filename>php://stderr</filename> allow direct access to the corresponding
input or output stream of the PHP process. The stream references a
duplicate file descriptor, so if you open <filename>php://stdin</filename>
and later close it, you close only your copy of the descriptor-the actual
stream referenced by <constant>STDIN</constant> is unaffected.
It is
recommended that you simply use the constants <constant>STDIN</constant>,
<constant>STDOUT</constant> and <constant>STDERR</constant> instead of
manually opening streams using these wrappers.
</simpara>
<simpara>
<filename>php://stdin</filename> is read-only, whereas
<filename>php://stdout</filename> and <filename>php://stderr</filename> are
write-only.
</simpara>
</refsect2>
<refsect2 xml:id="wrappers.php.input">
<title>php://input</title>
<simpara>
<filename>php://input</filename> is a read-only stream that allows you to
read raw data from the request body.
<filename>php://input</filename> is not available in POST requests with
<literal>enctype="multipart/form-data"</literal> if
<link linkend="ini.enable-post-data-reading">enable_post_data_reading</link>
option is enabled.
</simpara>
</refsect2>
<refsect2 xml:id="wrappers.php.output">
<title>php://output</title>
<para>
<filename>php://output</filename> is a write-only stream that allows you to
write to the output buffer mechanism in the same way as
<function>print</function> and <function>echo</function>.
</para>
</refsect2>
<refsect2 xml:id="wrappers.php.fd">
<title>php://fd</title>
<simpara>
<filename>php://fd</filename> allows direct access to the given file
descriptor. For example, <filename>php://fd/3</filename> refers to file
descriptor 3.
</simpara>
</refsect2>
<refsect2 xml:id="wrappers.php.memory">
<title>php://memory and php://temp</title>
<simpara>
<filename>php://memory</filename> and <filename>php://temp</filename> are
read-write streams that allow temporary data to be stored in a file-like
wrapper. One difference between the two is that
<filename>php://memory</filename> will always store its data in memory,
whereas <filename>php://temp</filename> will use a temporary file once the
amount of data stored hits a predefined limit (the default is 2 MB). The
location of this temporary file is determined in the same way as the
<function>sys_get_temp_dir</function> function.
</simpara>
<simpara>
The memory limit of <filename>php://temp</filename> can be controlled by
appending <literal>/maxmemory:NN</literal>, where <literal>NN</literal> is
the maximum amount of data to keep in memory before using a temporary
file, in bytes.
</simpara>
<caution>
<simpara>
Some PHP extensions may require a standard IO stream,
and may attempt to cast a given stream to a standard IO stream.
This cast can fail for memory streams as it requires the C
<function>fopencookie</function> function to be available.
This C function is <emphasis>not</emphasis> available on Windows.
</simpara>
</caution>
</refsect2>
<refsect2 xml:id="wrappers.php.filter">
<title>php://filter</title>
<simpara>
<filename>php://filter</filename> is a kind of meta-wrapper designed to
permit the application of <link linkend="filters">filters</link> to a
stream at the time of opening. This is useful with all-in-one file
functions such as <function>readfile</function>,
<function>file</function>, and <function>file_get_contents</function>
where there is otherwise no opportunity to apply a filter to the stream
prior the contents being read.
</simpara>
<para>
The <filename>php://filter</filename> target takes the following parameters
as part of its path. Multiple filter chains can be specified on one path.
Please refer to the examples for specifics on using these parameters.
</para>
<para>
<table>
<title>php://filter parameters</title>
<tgroup cols="2">
<thead>
<row>
<entry>Name</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<literal>resource=<stream to be filtered></literal>
</entry>
<entry>
This parameter is required. It specifies the stream that you would
like to filter.
</entry>
</row>
<row>
<entry>
<literal>read=<filter list to apply to read chain></literal>
</entry>
<entry>
This parameter is optional. One or more filter names can be provided
here, separated by the pipe character (<literal>|</literal>).
</entry>
</row>
<row>
<entry>
<literal>write=<filter list to apply to write chain></literal>
</entry>
<entry>
This parameter is optional. One or more filter names can be provided
here, separated by the pipe character (<literal>|</literal>).
</entry>
</row>
<row>
<entry>
<literal><filter list to apply to both chains></literal>
</entry>
<entry>
Any filter lists which are not prefixed by <literal>read=</literal>
or <literal>write=</literal> will be applied to both the read and
write chains as appropriate.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect2>
</refsect1>
<refsect1 role="options"><!-- {{{ -->
&reftitle.options;
<para>
<table>
<title>
Wrapper Summary (for <literal>php://filter</literal>, refer to the
summary of the wrapper being filtered)
</title>
<tgroup cols="2">
<thead>
<row>
<entry>Attribute</entry>
<entry>Supported</entry>
</row>
</thead>
<tbody>
<row>
<entry>Restricted by <link linkend="ini.allow-url-fopen">allow_url_fopen</link></entry>
<entry>No</entry>
</row>
<row>
<entry>Restricted by <link linkend="ini.allow-url-include">allow_url_include</link></entry>
<entry>
<literal>php://input</literal>,
<literal>php://stdin</literal>,
<literal>php://memory</literal> and
<literal>php://temp</literal> only.
</entry>
</row>
<row>
<entry>Allows Reading</entry>
<entry>
<literal>php://stdin</literal>,
<literal>php://input</literal>,
<literal>php://fd</literal>,
<literal>php://memory</literal> and
<literal>php://temp</literal> only.
</entry>
</row>
<row>
<entry>Allows Writing</entry>
<entry>
<literal>php://stdout</literal>,
<literal>php://stderr</literal>,
<literal>php://output</literal>,
<literal>php://fd</literal>,
<literal>php://memory</literal> and
<literal>php://temp</literal> only.
</entry>
</row>
<row>
<entry>Allows Appending</entry>
<entry>
<literal>php://stdout</literal>,
<literal>php://stderr</literal>,
<literal>php://output</literal>,
<literal>php://fd</literal>,
<literal>php://memory</literal> and
<literal>php://temp</literal> only. (Equivalent to writing)
</entry>
</row>
<row>
<entry>Allows Simultaneous Reading and Writing</entry>
<entry>
<literal>php://fd</literal>,
<literal>php://memory</literal> and
<literal>php://temp</literal> only.
</entry>
</row>
<row>
<entry>Supports <function>stat</function></entry>
<entry>
No. However, <literal>php://memory</literal> and
<literal>php://temp</literal> support <function>fstat</function>.
</entry>
</row>
<row>
<entry>Supports <function>unlink</function></entry>
<entry>No</entry>
</row>
<row>
<entry>Supports <function>rename</function></entry>
<entry>No</entry>
</row>
<row>
<entry>Supports <function>mkdir</function></entry>
<entry>No</entry>
</row>
<row>
<entry>Supports <function>rmdir</function></entry>
<entry>No</entry>
</row>
<row>
<entry>Supports <function>stream_select</function></entry>
<entry>
<literal>php://stdin</literal>,
<literal>php://stdout</literal>,
<literal>php://stderr</literal>,
<literal>php://fd</literal> and
<literal>php://temp</literal> only.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1> <!-- }}} -->
<refsect1 role="examples"><!-- {{{ -->
&reftitle.examples;
<example><!-- {{{ -->
<title>php://temp/maxmemory</title>
<para>
This optional parameter allows setting the memory limit before
<filename>php://temp</filename> starts using a temporary file.
</para>
<programlisting role="php">
<![CDATA[
<?php
// Set the limit to 5 MB.
$fiveMBs = 5 * 1024 * 1024;
$fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+');
fputs($fp, "hello\n");
// Read what we have written.
rewind($fp);
echo stream_get_contents($fp);
?>
]]>
</programlisting>
</example><!-- }}} -->
<example><!-- {{{ -->
<title>php://filter/resource=<stream to be filtered></title>
<para>
This parameter must be located at
the end of your <filename>php://filter</filename> specification and
should point to the stream which you want filtered.
</para>
<programlisting role="php">
<![CDATA[
<?php
/* This is equivalent to simply:
readfile("http://www.example.com");
since no filters are actually specified */
readfile("php://filter/resource=http://www.example.com");
?>
]]>
</programlisting>
</example><!-- }}} -->
<example><!-- {{{ -->
<title>php://filter/read=<filter list to apply to read chain></title>
<para>
This parameter takes one or more
filternames separated by the pipe character <literal>|</literal>.
</para>
<programlisting role="php">
<![CDATA[
<?php
/* This will output the contents of
www.example.com entirely in uppercase */
readfile("php://filter/read=string.toupper/resource=http://www.example.com");
/* This will do the same as above
but will also ROT13 encode it */
readfile("php://filter/read=string.toupper|string.rot13/resource=http://www.example.com");
?>
]]>
</programlisting>
</example><!-- }}} -->
<example><!-- {{{ -->
<title>php://filter/write=<filter list to apply to write chain></title>
<para>
This parameter takes one or more
filternames separated by the pipe character <literal>|</literal>.
</para>
<programlisting role="php">
<![CDATA[
<?php
/* This will filter the string "Hello World"
through the rot13 filter, then write to
example.txt in the current directory */
file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World");
?>
]]>
</programlisting>
</example><!-- }}} -->
<example>
<title>php://memory and php://temp are not reusable</title>
<para>
<filename>php://memory</filename> and <filename>php://temp</filename>
are not reusable, i.e. after the streams have been closed there is no way
to refer to them again.
</para>
<programlisting role="php">
<![CDATA[
<?php
file_put_contents('php://memory', 'PHP');
echo file_get_contents('php://memory'); // prints nothing
]]>
</programlisting>
</example>
</refsect1><!-- }}} -->
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->