Forum und email
file_get_contents

file_get_contents

(PHP 4 >= 4.3.0, PHP 5)

file_get_contents -- Reads entire file into a string

Opis

string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )

Identical to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen 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. It will use memory mapping techniques if supported by your OS to enhance performance.

Notatka: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().

Notatka: context parameter can be skipped by NULL.

Rejestr zmian

WersjaOpis
5.0.0 Added the context support.
5.1.0 Added the offset and maxlen parameters.

Notatki

Notatka: Ta funkcja jest bezpieczna dla danych binarnych.

Podpowiedź: Jeśli włączona jest dyrektywa konfiguracyjna fopen wrappers, możliwe jest podanie jako nazwy pliku adresu URL. Zobacz opis funkcji fopen() aby dowiedzieć się jak przekazać nazwę pliku, oraz fopen wrappers aby uzyskać listę obsługiwanych protokołów.

Notatka: Wsparcie dla kontekstów zostało dodane w PHP 5.0.0. Opis kontekstów znajduje się w rozdziale Materiały źródłowe CLVIII, Stream Functions.

Ostrzeżenie

Łącząc się przez SSL, serwer Microsoft IIS pogwałca reguły protokołu przez zamknięcie połączenia bez wysłania znacznika close_notify. PHP zgłosi to jako "SSL: Fatal Protocol Error" po przesłaniu całości danych. Aby obejść ten błąd, wystarczy obniżyć poziom raportowania błędów (error_reporting) aby nie były wyświetlane ostrzeżenia. PHP w wersji 4.3.7 i nowsze wykrywa obecność zepsutego serwera IIS przy otwieraniu strumienia przez wrapper https:// i wyłącza wyświetlanie tych ostrzeżeń. Używając funkcji fsockopen() do otwarcia gniazda ssl:// należy samemu zatroszczyć się o wyłączenie ostrzeżeń.