PHP is_file () function usage Guide, is_file usage Guide _php tutorial

Source: Internet
Author: User

PHP is_file () function usage Guide, is_file usage guide


The Is_file () function checks whether the specified file name is normal.

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 file exists and is a normal file.

Let's take a look at one example:

<?phpvar_dump (Is_file (' A_file.txt ')). "\ n"; Var_dump (Is_file ('/usr/bin/')). "\ n";? >

The example above will output:
BOOL (TRUE)
BOOL (FALSE)

Example two:

<?phpfunction Isfile ($file) {return Preg_match ('/^[^.^:^?^-][^:^?] *. (? i) '. Getexts (). ' $/', $file);//first character cannot be. : ? -subsequent characters can ' t be a:?//then A. Character and must end with one of your extentions//getexts () can is replaced with your extentions pattern}function getext S () {//list acceptable file extensions Herereturn ' (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 three:

<?phpfunction 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 will delete all files and folders.

The above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/996222.html www.bkjia.com true http://www.bkjia.com/PHPjc/996222.html techarticle in PHP, the Is_file () function uses the guide, is_file Use the Guide is_file () function to check if the specified file name is a normal document. Is_file-tells whether the filename is a regular file ...

  • 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.