PHP reads files and supports code sharing of remote files. Php file reading case 1 copy the code as follows :? Php $ filejb51.net. php; this case does not support remote $ fsofopen ($ file, r); echo $ datafread ($ fso, filesize ($ file); fcl php reads files
Case 1
The code is as follows:
$ File = 'jb51. net. php ';
// Remote connection is not supported in this case.
$ Fso = fopen ($ file, 'r ');
Echo $ data = fread ($ fso, filesize ($ file ));
Fclose ($ fso );
?>
Fopen () binds the name resource specified by file to a stream.
Filesize: the number of bytes of the file size. If an error occurs, FALSE is returned.
Note: Because the integer type of PHP is signed, and most platforms use 32-bit integers, the filesize () function may return unexpected results when encountering a file larger than 2 GB. for files between 2 GB and 4 GB, sprintf ("% u", filesize ($ file) can be used to overcome this problem.
Fread () reads a maximum of length bytes from the file pointer handle. this function reads the length of several bytes, or when it reaches the EOF, or (for network streams) when a package is available, it stops reading files, depending on the first situation.
Note: Usage of earlier versions! We recommend that you use file_get_contents for php5.
Case 2
The code is as follows:
$ File = 'jb51. net. php ';
// Remote support
$ File = 'http: // www.jb51.net ';//
Echo $ data = implode ('', file ($ file ));
?>
File-read the entire file into an array
Description
Read binary files
Case 3
The code is as follows:
$ File = 'http: // www.jb51.net ';
Echo file_get_contents ($ file );
?>
File_get_contents -- read the entire file into a string
Description
String file_get_contents (string filename [, int use_include_path [, resource context])
Like file (), only file_get_contents () is returned as a string.
The file_get_contents () function is the preferred method to read the file content into a string. if the operating system supports this function, the memory ing technology is used to improve the performance.
The code of the explain case is as follows :? Php $ file = 'jb51. net. php'; // remote $ fso = fopen ($ file, 'r'); echo $ data = fread ($ fso, filesize ($ file) is not supported in this case )); fcl...