PHP 输入/输出流

一、PHP有以下几种输入/输出流: php://stdin php://stdout php://stderr php://output php://input php://filter

二、几种流的简单介绍:

php://stdin, php://stdout和php://stderr允许访问php进程相应的输入或者输出流

php://output允许向输出缓冲机制写入数据,和print()与echo()的方式相同

php://input允许你读取POST原始数据。和$HTTP_RAW_POST_DATA比起来,它给内存带来的压力小,并且不需要任何特殊的php.ini设置

php://stdin和php://input是只读的,同时,php://stdout,php://stderr和php://output是只写的。

php://filter是一种设计用来允许过滤器程序在打开时成为流的封装协议。这对于单独具有完整功能的文件函数readfile(),file()和file_get_content()很有用,否则就没有机会在读取内容之前将过滤器应用于流之上。

php://filter的目标接受随后的‘参数’作为‘路径’的一部分。

/resource=<stream to be filtered> (required) 此参数必须位于 php://filter 的末尾并且需要指向向要过滤的流。

<!-- lang: php -->
<?php
<!-- lang: php -->
/* This is equivalent to simply:
<!-- lang: php -->
   readfile("http://www.example.com");
<!-- lang: php -->
   since no filters are actually specified */
<!-- lang: php -->

<!-- lang: php -->
readfile("php://filter/resource=http://www.example.com");
<!-- lang: php -->
?>

/read=<filter list to apply to read chain> (optional) 本参数接受一个或多个过滤器的名字,用管道字符 | 分隔。

<!-- lang: php -->
<?php
<!-- lang: php -->
/* This will output the contents of
<!-- lang: php -->
   www.example.com entirely in uppercase */
<!-- lang: php -->
readfile("php://filter/read=string.toupper/resource=http://www.example.com");
<!-- lang: php -->

<!-- lang: php -->
/* This will do the same as above
<!-- lang: php -->
   but will also ROT13 encode it */
<!-- lang: php -->
readfile("php://filter/read=string.toupper|string.rot13/resource=http://www.example.com");
<!-- lang: php -->
?>

/write=<filter list to apply to write chain> (optional) 本参数接受一个或多个过滤器的名字,用管道字符 | 分隔。

<!-- lang: php -->
<?php
<!-- lang: php -->
/* This will filter the string "Hello World"
<!-- lang: php -->
   through the rot13 filter, then write to
<!-- lang: php -->
   example.txt in the current directory */
<!-- lang: php -->
file_set_contents("php://filter/write=string.rot13/resource=example.txt","Hello World");
<!-- lang: php -->
?>

/<filter list to apply to both chains> (optional) 任何没有被 read= 或 write= 指定的过滤器会被同时应用于读写链。

转载于:https://my.oschina.net/syc2013/blog/187972

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值