《PHP學習:PHP中is_file()函數(shù)使用指南》要點:
本文介紹了PHP學習:PHP中is_file()函數(shù)使用指南,希望對您有用。如果有疑問,可以聯(lián)系我們。
is_file() 函數(shù)檢查指定的文件名是否是正常的文件.
PHP應(yīng)用
is_file ― Tells whether the filename is a regular filePHP應(yīng)用
用法:
bool is_file ( string $filename ) $file 為必選參數(shù)
如果文件存在且為正常的文件則返回 TRUE.PHP應(yīng)用
先來看一個實例一:PHP應(yīng)用
<?php var_dump(is_file('a_file.txt')) . "\n"; var_dump(is_file('/usr/bin/')) . "\n"; ?>
上例將輸出:
bool(true)
bool(false)PHP應(yīng)用
實例二:PHP應(yīng)用
<?php function 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 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'); ?>
實例三:PHP應(yīng)用
<?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); } } } } } ?>
此函數(shù)將刪除所有文件與文件夾.PHP應(yīng)用
以上所述便是本文的全部內(nèi)容了,希望大家能夠喜歡.PHP應(yīng)用
歡迎參與《PHP學習:PHP中is_file()函數(shù)使用指南》討論,分享您的想法,維易PHP學院為您提供專業(yè)教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/10933.html