• PHP 输入/输出流


    自 PHP 4.3.0 起支持 php://output 和 php://input,自 PHP 5.0.0 起支持 php://filter。
    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://input 不能用于 enctype=“multipart/form-data”。

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

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

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

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

    <?php /* This is equivalent to simply: readfile("http://www.example.com"); since 否 filters are actually specified */ readfile("php://filter/resource=http://www.example.com"); ?>

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

    <?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"); ?>

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

    <?php /* 下面的语句将使用 rot13 过滤器过滤 "Hello World" 字符串,并写入当前目录下的 example.txt */ file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World"); ?>

    / (optional) 任何没有被 read= 或 write= 指定的过滤器会被同时应用于读写链。

    表格 L-6. 封装协议摘要(对于 php://filter,是指被过滤的封装器摘要。)

    属性 支持
    受限于 allow_url_fopen。 否
    允许读取 仅在 php://stdin 和 php://input 中允许。
    允许写入 仅在 php://stdout, php://stderr, 和 php://output 中允许。
    允许附加 仅在 php://stdout, php://stderr, 和 php://output 中允许 (与写入相同)。
    允许同时读写 否。这些封装器是单向的。
    支持 stat() 否
    支持 unlink() 否
    支持 rename() 否
    支持 mkdir() 否
    支持 rmdir() 否


    作者:vaal_water
    来源:CSDN
    原文:https://blog.csdn.net/vaal_water/article/details/5892643

  • 相关阅读:
    Christmas Jump(k_push)
    cloudyarn(k_push)
    Eye sketch
    Candy Treasure Box
    Active Ball
    Lotus words
    Super Fish
    [POJ2436] Disease Management
    [bzoj3376] Cube Stacking 方块游戏
    [POJ3009] Curling 2.0
  • 原文地址:https://www.cnblogs.com/yumingzhao/p/10937963.html
Copyright © 2020-2023  润新知