PHP中is_file()函数使用指南
is_file()函数检查指定的文件名是否是正常的文件。
is_file—Tellswhetherthefilenameisaregularfile
用法:
boolis_file(string$filename)$file为必选参数
如果文件存在且为正常的文件则返回TRUE。
先来看一个实例一:
<?php
var_dump(is_file('a_file.txt'))."\n";
var_dump(is_file('/usr/bin/'))."\n";
?>
上例将输出:
bool(true)
bool(false)
实例二:
<?php
functionisfile($file){
returnpreg_match('/^[^.^:^?^-][^:^?]*.(?i)'.getexts().'$/',$file);
//firstcharactercannotbe.:?-subsequentcharacterscan'tbea:?
//thena.characterandmustendwithoneofyourextentions
//getexts()canbereplacedwithyourextentionspattern
}
functiongetexts(){
//listacceptablefileextensionshere
return'(app|avi|doc|docx|exe|ico|mid|midi|mov|mp3|
mpg|mpeg|pdf|psd|qt|ra|ram|rm|rtf|txt|wav|word|xls)';
}
echoisfile('/Users/YourUserName/Sites/index.html');
?>
实例三:
<?php
functiondeletefolder($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);
}
}
}
}
}
?>
此函数将删除所有文件与文件夹。
以上所述就是本文的全部内容了,希望大家能够喜欢。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下