The is_file () function used by php to determine whether a file is used

Source: Internet
Author: User
The is_file () function used by php to determine whether a file is used

  1. Var_dump(is_file('a_file.txt '). "\ n ";
  2. Var_dump (is_file ('/usr/bin/'). "\ n ";
  3. ?>

Output: bool (true) bool (false)

Example 2:

  1. Function isfile ($ file ){
  2. Return preg_match ('/^ [^. ^: ^? ^-] [^: ^?] *.(? I) '. getexts ().' $/', $ file );
  3. // First character cannot be .:? -Subsequent characters can't be :?
  4. // Then a. character and must end with one of your extentions
  5. // Getexts () can be replaced with your extentions pattern
  6. }
  7. Function getexts (){
  8. // List acceptable file extensions here
  9. Return '(app | avi | doc | docx | exe | ico | mid | midi | mov | mp3 |
  10. Mpg | mpeg | pdf | psd | qt | ra | ram | rm | rtf | txt | wav | word | xls )';
  11. }
  12. Echo isfile ('/Users/YourUserName/Sites/index.html ');
  13. ?>

Example 3:

  1. Function deletefolder ($ path)
  2. {
  3. If ($ handle = opendir ($ path ))
  4. {
  5. While (false! ==( $ File = readdir ($ handle )))
  6. {
  7. If ($ file <> "." AND $ file <> "..")
  8. {
  9. If (is_file ($ path. '/'. $ file ))
  10. {
  11. @ Unlink ($ path. '/'. $ file );
  12. }
  13. If (is_dir ($ path. '/'. $ file ))
  14. {
  15. Deletefolder ($ path. '/'. $ file );
  16. @ Rmdir ($ path. '/'. $ file );
  17. }
  18. }
  19. }
  20. }
  21. }
  22. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.