Home  >  Article  >  Backend Development  >  Translation: PHP php://

Translation: PHP php://

WBOY
WBOYforward
2023-08-26 22:09:19797browse

翻译:PHP php://

Introduction

php://The wrapper supports access to various I/O streams. This includes standard input, output, and error streams. In-memory, disk-backed, and filtered streams are also accessible via the php:// protocol.

Standard stream

php://stdin, php://stdout and php://stderr respectively Allows the PHP process direct access to the standard input stream device, standard output stream, and error stream. The predefined constants STDIN, STDOUT, and STDERR represent these streams respectively.

php://input

php://input Allows read-only access to the raw data contained in the body of the HTTP request. Note that the same data is available in the $HTTP_POST_RAW-DATA variable (now deprecated). However, php://input does not work when the enctype attribute is set to multipart/form-data

php://output

This wrapper represents a write-only stream, Allows buffering mechanisms, similar to print and echo statements.

php://fd

a file descriptor is accessible through this wrapper. The standard streams STDIN, STDOUT, and STDERR are assigned file descriptors 1, 2, and 3. Every other stream is assigned an incrementing file descriptor. So php://fd/5 refers to file descriptor 5

php://memory

which is a read/write stream that allows data to be stored temporarily in memory. php://temp Wrapper is similar. However, in the latter case, the data is stored in temporary files instead of in memory.

php://filter

This wrapper allows a filter to be applied to a stream while the stream is being filtered. Open. Filters are particularly useful for the readfile(), file_get_contents(), and file() functions.

Example

In the following example, console input is read from php://stdin and used php://stdout

Show output
<?php
$file=fopen("php://stdin","r");
$x=fread($file,10);
echo $x;
$out=fopen("php://stdout","w");
fwrite($out, $x);
fclose($file);
?>

php://input Stream wrapper allows getting raw data from HTTP requests. In the example below, an HTML form uses the POST method to send data to a PHP script

<html>
<body>
<form action="testscript.php" method="POST">
   <input type="text" name="name">
   <input type="text" name="age">
   <input type ="submit" value="submit">
</form>
</body>
</html>

The PHP script to retrieve the raw HTTP data is as follows -

<?php
$json = file_get_contents("php://input");
$data = json_decode($json);
print_r($json);
?>

The above is the detailed content of Translation: PHP php://. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete