PHP is_file () function Use Guide _php instance

Source: Internet
Author: User

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

Is_file-tells whether the filename is a regular file

Usage:
BOOL Is_file (string $filename) $file for required parameters
Returns TRUE if the file exists and is a normal file.

Let's take a look at one example first:

<?php
var_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:

<?php
function Isfile ($file) {return
preg_match ('/^[^.^:^?^-][^:^?] *. (? i) '. Getexts (). ' $/', $file);
The character cannot is. : ? -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 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 three:

<?php
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 mentioned is the entire content of this article, I hope you can enjoy.

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.