zoukankan      html  css  js  c++  java
  • php输入输出流

    PHP 3.0.13 及以上版本,自 PHP 4.3.0 起支持 php://outputphp://input,自 PHP 5.0.0 起支持 php://filter

    • php://stdin

    • php://stdout

    • php://stderr

    • php://output

    • php://input

    • php://filter

    php://stdinphp://stdoutphp://stderr 允许访问 PHP 进程相应的输入或者输出流。

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

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

    php://stdinphp://input 是只读的,同时,php://stdoutphp://stderrphp://output 是只写的。

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

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

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

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

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

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

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

    表格 I-5. Wrapper Summary (For php://filter, refer to summary of wrapper being filtered.)

    属性
    支持

    Restricted by allow_url_fopen.
    No

    Allows Reading
    php://stdin and php://input only.

    Allows Writing
    php://stdout, php://stderr, and php://output only.

    Allows Appending
    php://stdout, php://stderr, and php://output only. (Equivalent to writing)

    Allows Simultaneous Reading and Writing
    No. These wrappers are unidirectional.

    Supports stat()
    No

    Supports unlink()
    No

  • 相关阅读:
    HDU 5918 SequenceI (2016 CCPC长春站 KMP模版变形)
    HDU 4585 Shaolin (set的应用)
    HDU 4329 MAP(stringstream的用法)
    CodeForces 698B Fix a Tree (并查集应用)
    UVALive 2520 Holedox Moving(BFS+状态压缩)
    UVA
    毛竹
    kmp
    博弈论
    最长回文子串
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/2787293.html
Copyright © 2011-2022 走看看