[PHP] PHP I/O流访问的封装 →→→→→进入此内容的聊天室

来自 , 2020-04-09, 写在 PHP, 查看 111 次.
URL http://www.code666.cn/view/20c86a62
  1. //在使用 readfile(),file_get_contents(),stream_get_contents()之类的函数使,可以使用过滤器应用在打开的stream上
  2.  
  3. // 写入时用 str_rot13() 函数处理所有的流数据
  4. file_put_contents("php://filter/write=string.rot13/resource=file:///path/to/somefile.txt","Hello World");
  5.  
  6. //也可以使用下面的方式
  7. $h = fopen('test.txt', 'r');
  8. stream_filter_append($h, 'string.rot13');
  9.  
  10. // Read data and encode/decode
  11. readfile("php://filter/read=string.toupper|string.rot13/resource=http://www.google.com");
  12.  
  13.  
  14.  
  15.  
  16.  
  17. $opts = array(
  18.   'http'=>array(
  19.     'method'=>"POST",
  20.     'header'=> "Auth: SecretAuthTokenrn" .
  21.                "Content-type: application/x-www-form-urlencodedrn" .
  22.                "Content-length: " . strlen("Hello World"),
  23.     'content' => 'Hello World'
  24.   )
  25. );
  26. $default = stream_context_get_default($opts);
  27. readfile('http://localhost/dev/streams/php_input.php',false,$default);
  28. //我们模拟了一个POST包
  29. //查看 php_input.php 的 apache_request_headers() 会显示结果
  30.  
  31. (
  32.     [Host] => localhost
  33.     [Auth] => SecretAuthToken
  34.     [Content-type] => application/x-www-form-urlencoded
  35.     [Content-length] => 11
  36. )
  37.  

回复 "PHP I/O流访问的封装"

这儿你可以回复上面这条便签

captcha