Forum und email

PHP 입력/출력(input/output) 스트림

PHP 3.0.13 이후의, php://output PHP 4.3.0 이후의 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://outputprint()echo() 같은 출력 버퍼 메카니즘에 대한 쓰기 권한을 허용한다.

php://input은 raw POST 데이터를 읽을수 있는 권한을 허용한다. $HTTP_RAW_POST_DATA에 대한 메모리 집적에 대한 차선책이고, 특별한 php.ini 디렉티브 설정이 필요치 않다.

php://stdinphp://input 은 읽기 전용, 반면에 php://stdout, php://stderrphp://output 쓰기 전용이다.

php://filter는 스트림을 열때 필터의 응용을 허용하도록 설계된 메타-래퍼(meta-wrapper)의 한 종류이다. 컨텐츠를 읽기전에 스트림에 대한 필터를 적용할 기회가 전혀 없는 readfile(), file(), file_get_contents() 같은 올-인-원(all-in-one) 함수에 대한 가용성을 갖는다.

php://filter 타겟은 그 'path'의 부분으로서 다음 'parameters'를 취한다.

  • /resource=<필터링되는 스트림> (필수) 이 인자는 php://filter 사양의 끝부분에 위치해야 하고 필터링을 원하는 스트림을 가리켜야 한다.

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

    readfile("php://filter/resource=https://www.example.com");
    ?>

  • /read=<읽기 체인에 적용되는 필터 리스트> (선택적) 이 인자는 | 파이프 문자로 구분되는 하나이상의 필터명이 적용된다.

    <?php
    /* This will output the contents of 
       www.example.com entirely in uppercase */
    readfile("php://filter/read=string.toupper/resource=https://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=https://www.example.com");
    ?>

  • /write=<쓰기 체인에 적용되는 필터 리스트> (선택적) 이 인자는 | 파이프 문자로 구분하는 하나이상의 필터명을 적용합니다.

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

  • <양쪽 체인에 적용되는 필터 리스트> (선택적) read=write=에 선행하지 않는 모든 필터 목록은 읽기와 쓰기 양쪽 모두의 체인에 (적절하게) 적용합니다.

래퍼(Wrapper) 요약(php://filter에 대한, 필터링 되는 래퍼의 요약으로 참조됨.)
속성 지원
allow_url_fopen으로 제한 No
읽기 허용 php://stdin, php://input 전용.
쓰기 허용 php://stdout, php://stderr, php://output 전용.
추가 허용 php://stdout, php://stderr, php://output only. (쓰기와 동일)
동시 읽기/쓰기 허용 No. 이 래퍼는 방향성을 갖지 않는다.
stat() 지원 No
unlink() 지원 No
rename() 지원 No
mkdir() 지원 No
rmdir() 지원 No