file_get_contents in php code example

Example 1: php get file contents

<?php
file_get_contents("file.txt");
?>

Example 2: php file_get_contents

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>

Example 3: turn text file to string php

$fileContent = file_get_contents($url);

Example 4: transfer file using file_get_content

file_get_contents('http://url/to/upload/handler', false, $context);

Example 5: file_get_contents('php //input')

Actually 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://input is not available with enctype="multipart/form-data".

Reference: http://php.net/manual/en/wrappers.php.php

Example 6: transfer file using file_get_content

$header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY;

Tags:

Php Example