The is_file () function used by php to determine whether a file is used
- Var_dump(is_file('a_file.txt '). "\ n ";
- Var_dump (is_file ('/usr/bin/'). "\ n ";
- ?>
-
Output: bool (true) bool (false) Example 2:
- 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:
- 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 );
- }
- }
- }
- }
- }
- ?>
|