这段php代码详细演示了如何打开文件、读取文件和关闭文件,php中可以通过fopen打开文件,通过filesize函数获取文件大小,fread读取文件内容,fclose关闭文件 - Reading a file using PHP
-
- $filename = "/home/user/guest/tmp.txt";
- $file = fopen( $filename, "r" );
- if( $file == false )
- {
- echo ( "Error in opening file" );
- exit();
- }
- $filesize = filesize( $filename );
- $filetext = fread( $file, $filesize );
-
- fclose( $file );
-
- echo ( "File size : $filesize bytes" );
- echo ( "
$filetext " ); - ?>
-
|