Reading Files in PHP
There are several ways to open and display files, and each has its uses. You don’t need to know all the ways to read filesit is probably best to learn one and stick with it for your own code. However, you will almost certainly come across each of these methods in other people’s code, because everyone has her own method of getting things done.
readfile( )
If you want to output a file to the screen without doing any form of text processing on it whatsoever, readfile( ) is the easiest function to use. When passed a filename as its only parameter, readfile( ) will attempt to open it, read it all into memory, then output it without further question. If successful, readfile( ) will return an integer equal to the number of bytes read from the file.
If unsuccessful, readfile( ) will return false, and there are quite a few reasons why it may fail. For example, the file might not exist, or it might exist with the wrong permissions.
Here is an example script:
Popularity: 9% [?]













last comments