//在使用 readfile(),file_get_contents(),stream_get_contents()之类的函数使,可以使用过滤器应用在打开的stream上 |
// 写入时用 str_rot13() 函数处理所有的流数据 |
file_put_contents ( "php://filter/write=string.rot13/resource=file:///path/to/somefile.txt" , "Hello World" ); |
//也可以使用下面的方式 |
$h = fopen ( 'test.txt' , 'r' ); |
stream_filter_append( $h , 'string.rot13' ); |
// Read data and encode/decode |
readfile( "php://filter/read=string.toupper|string.rot13/resource=http://www.google.com" ); |
$opts = array ( |
'http' => array ( |
'method' => "POST" , |
'header' => "Auth: SecretAuthTokenrn" . |
"Content-type: application/x-www-form-urlencodedrn" . |
"Content-length: " . strlen ( "Hello World" ), |
'content' => 'Hello World' |
) |
); |
$default = stream_context_get_default( $opts ); |
readfile( 'http://localhost/dev/streams/php_input.php' ,false, $default ); |
//我们模拟了一个POST包 |
//查看 php_input.php 的 apache_request_headers() 会显示结果 |
Array |
( |
[Host] => localhost |
[Auth] => SecretAuthToken |
[Content-type] => application/x-www-form-urlencoded |
[Content-length] => 11 |
) |