Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain file_get_contents('php://input')

Tags:

android

php

I am writing an android app to connect to PHP web service and through my searches in internet I faced file_get_contents('php://input'); and I understood some parts of it's functionality but I still don't get it. What are php://input or php://stdin or stuff like that? I've read http://php.net/manual/en/function.file-get-contents.php and I confused much more.

Please explain it completely.

like image 211
hamidfzm Avatar asked Apr 25 '14 23:04

hamidfzm


People also ask

What is the difference between file_get_contents () function and file () function?

file — Reads entire file contents into an array of lines. file_get_contents — Reads entire file contents into a string.

What does file_get_contents return?

This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to length bytes. On failure, file_get_contents() will return false . file_get_contents() is the preferred way to read the contents of a file into a string.

What does the second parameter of the file_get_contents () function do?

Open the file and set the path of the file from where the file will be read. The second argument of the file_get_contents() is required to set true or FILE_USE_INCLUDE_PATH to read the file from the path defined in the include_path parameter.

Does file_get_contents cache?

Short answer: No. file_get_contents is basically just a shortcut for fopen, fread, fclose etc - so I imagine opening a file pointer and freading it isn't cached.


1 Answers

The information comes from here: http://www.php.net/manual/en/wrappers.php.php

When information is sent to the server via a POST request, it is saved in a temporary file.

The command file_get_contents('php://input') reads the raw information sent to PHP -- unprocessed before it ever gets put into $_POST or $_REQUEST super globals.

This technique is often used when someone is uploading a file, such as an image.

EDIT: removed $_GET

like image 155
Jeremy J Starcher Avatar answered Oct 18 '22 15:10

Jeremy J Starcher