Home > Backend Development > PHP Tutorial > Guide to using is_file() function in PHP, guide to using is_file_PHP tutorial

Guide to using is_file() function in PHP, guide to using is_file_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:54:39
Original
920 people have browsed it

Guide to the use of is_file() function in PHP, guide to the use of is_file

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

Let’s look at an example one:

<&#63;php
var_dump(is_file('a_file.txt')) . "\n";
var_dump(is_file('/usr/bin/')) . "\n";
&#63;>
Copy after login

The above example will output:
bool(true)
bool(false)

Example 2:

<&#63;php
function isfile($file){
return preg_match('/^[^.^:^&#63;^-][^:^&#63;]*.(&#63;i)' . getexts() . '$/',$file);
//first character cannot be . : &#63; - subsequent characters can't be a : &#63;
//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');
&#63;>
Copy after login

Example 3:

<&#63;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);
}
}
}
}
}
&#63;>
Copy after login

This function will delete all files and folders.

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/996222.htmlTechArticleUsage Guide of is_file() function in PHP, is_file usage guide is_file() function checks whether the specified file name is normal file. is_file — Tells whether the filename is a regular file...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template