How to use related functions to read files in PHP. In? Php $ filedirlist. php; if (is_readable ($ file) false) {die (the file does not exist or cannot be read);} else {echo exists ;}? File_exists is also used to determine whether a file exists.
- <? Php
- $ File = 'dirlist. php ';
- If (is_readable ($ file)
= False ){
- Die ('file does not exist or cannot be read ');
- } Else {
- Echo 'exist ';
- }
- ?>
-
The file_exists function is used to determine the existence of the file (as shown below), but this is obviously not comprehensive. it can be used when a file exists.
- <? Php
- $ File = "filelist. php ";
- If (file_exists ($ file) = false ){
- Die ('file does not exist ');
- }
- $ Data = file_get_contents ($ file );
- Echo htmlentities ($ data );
- ?>
-
However, the file_get_contents function is not supported in earlier versions. you can create a handle for the file and then read all with pointers:
$ Fso = fopen ($ cacheFile, 'r ');
$ Data = fread ($ fso, filesize ($ cacheFile ));
Fclose ($ fso );
There is also a way to read binary files:
$ Data = implode ('', file ($ file ));
Why? Php $ file = 'dirlist. php '; if (is_readable ($ file) = false) {die ('file does not exist or cannot be read');} else {echo 'Exists ';}? File_exists (below...