php://input&是什么意思php://输出,何时需要使用? [英] What is the meaning of php://input & php://output and when it needs to use?
问题描述
php://input
&是什么意思php://output
以及何时需要使用?
请举例说明.
What is the meaning of php://input
& php://output
and when it needs to use?
Please explain with an example.
推荐答案
这是两个 fopen , stream_get_contents 等.
These are two of the streams that PHP provides. Streams can be used by functions like fopen, fwrite, stream_get_contents, etc.
php://input
是只读流,允许您读取发送给它的请求正文(如上载的文件或POST变量).
php://input
is a read-only stream that allows you to read the request body sent to it (like uploaded files or POST variables).
$request_body = stream_get_contents('php://input');
php://output
是可写流,已发送到服务器,并将返回给请求您页面的浏览器.
php://output
is a writable stream that is sent to the server and will be returned to the browser that requested your page.
$fp = fopen('php://output', 'w');
fwrite($fp, 'Hello World!'); //User will see Hello World!
fclose($fp);
请注意,如果您在CLI中,则php://output会将数据写入命令行.
Note that if you are in the CLI, php://output will write data to the command line.
这篇关于php://input&是什么意思php://输出,何时需要使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!