Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php://input - what does it do in fopen()?

Tags:

php

fopen

$handle = fopen("/home/rasmus/file.txt", "r");
$handle = fopen("/home/rasmus/file.gif", "wb");

I can understand this that /home/rasmus/file.txt and /home/rasmus/file.gif are the file path.

But what these mean:

php://input
php://temp

in

$objInputStream = fopen("php://input", "r");
$objTempStream = fopen("php://temp", "w+b");

What do they do?

like image 557
Run Avatar asked Aug 16 '11 19:08

Run


People also ask

What does php input do?

php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php. ini directives. php://stdin and php://input are read-only, whereas php://stdout, php://stderr and php://output are write-only.

When using the fopen () function to open a file in php What made should you use for appending data to a file?

You can append data into file by using a or a+ mode in fopen() function. Let's see a simple example that appends data into data. txt file.

What does stdin mean in php?

Standard streams php://stdin, php://stdout and php://stderr allow direct access to standard input stream device, standard output stream and error stream to a PHP process respectively. Predefined constants STDIN, STDOUT and STDERR respectively represent these streams.

When writing to an opened file stream which php function is used?

PHP | fopen( ) (Function open file or URL) - GeeksforGeeks.


2 Answers

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATAis not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

Check out the manual: http://php.net/manual/en/wrappers.php.php

like image 71
adritha84 Avatar answered Sep 28 '22 11:09

adritha84


php://temp stores data in a temporary file which is only accessible for the duration of the script's execution. It is a real file, but is cleaned up as soon as the script terminates unlike a true file opened with fopen(), that will persist on the filesystem.

php://input is used for reading the raw HTTP request body, without having the $_POST and $_SERVER variables abstracted out. The php://input stream would give access to the entire HTTP request as the server handed it to the PHP interpreter.

like image 27
Michael Berkowski Avatar answered Sep 28 '22 12:09

Michael Berkowski