PHP is_file () function User Guide. In PHP, the is_file () function in php is used to determine whether a file exists. the method of use is also very simple. For more information, see. How to use is_file () function in PHP
In php, the is_file () function is used to determine whether a file exists. it is also very simple to use. if you need it, refer to it.
The is_file () function checks whether the specified file name is a normal file.
Is_file-Tells whether the filename is a regular file
Usage:
Bool is_file (string $ filename) $ file is a required parameter
Returns TRUE if the object exists and is normal.
Let's take a look at Example 1:
?
|
1
2
3
4 |
Var_dump(is_file('a_file.txt '). "\ n ";
Var_dump (is_file ('/usr/bin/'). "\ n ";
?>
|
The above example will output:
Bool (true)
Bool (false)
Example 2:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
Function isfile ($ file ){
Return preg_match ('/^ [^. ^: ^? ^-] [^: ^?] *.(? I) '. getexts ().' $/', $ file );
// First character cannot be .:? -Subsequent characters can't be :?
// Then a. character and must end with one of your extentions
// Getexts () can be replaced with your extentions pattern
}
Function getexts (){
// List acceptable file extensions here
Return '(app | avi | doc | docx | exe | ico | mid | midi | mov | mp3 |
Mpg | mpeg | pdf | psd | qt | ra | ram | rm | rtf | txt | wav | word | xls )';
}
Echo isfile ('/Users/YourUserName/Sites/index.html ');
?>
|
Example 3:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
Function deletefolder ($ path)
{
If ($ handle = opendir ($ path ))
{
While (false! ==( $ File = readdir ($ handle )))
{
If ($ file <> "." AND $ file <> "..")
{
If (is_file ($ path. '/'. $ file ))
{
@ Unlink ($ path. '/'. $ file );
}
If (is_dir ($ path. '/'. $ file ))
{
Deletefolder ($ path. '/'. $ file );
@ Rmdir ($ path. '/'. $ file );
}
}
}
}
}
?>
|
This function deletes all files and folders.
The above is all the content of this article. I hope you will like it.
The is_file () function in php is used to determine whether a file exists. it is also very easy to use. if you need it, you can refer to it. Is_file () function check...