- $ File = 'jbxue. com. php ';
- // Remote access is not supported
- $ 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. Example 2,
- $ File = 'jbxue. com. php ';
- // Remote support
- $ File = 'http: // bbs.it-home.org ';//
- Echo $ data = implode ('', file ($ file ));
- ?>
File-read the entire file into an array to read binary files. Example 3,
- $ File = 'http: // bbs.it-home.org ';
- Echo file_get_contents ($ file );
- ?>
File_get_contents -- read the entire file into a string indicating that string file_get_contents (string filename [, int use_include_path [, resource context]) is the same as file (), except for file_get_contents () returns the object as a string. the file_get_contents () function is used to read the file content into a string. if the operating system supports it, the memory ing technology will be used to enhance the performance. I have shared the code for getting remote files in three php examples. I hope it will be helpful to you. |