国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP中is_file()函數使用指南

2024-09-04 11:42:39
字體:
來源:轉載
供稿:網友

php中is_file()函數是用來判斷文件是否存在,使用方法也非常的簡單,有需要的小伙伴可以參考下。

is_file() 函數檢查指定的文件名是否是正常的文件。

is_file — Tells whether the filename is a regular file

用法:bool is_file ( string $filename ) $file 為必選參數

如果文件存在且為正常的文件則返回 TRUE。

先來看一個實例一:

  1. <?php 
  2. var_dump(is_file('a_file.txt')) . "/n"
  3. var_dump(is_file('/usr/bin/')) . "/n"
  4. ?> 

上例將輸出:

bool(true)

bool(false)

實例二:

  1. <?php 
  2. function isfile($file){ 
  3. return preg_match('/^[^.^:^?^-][^:^?]*.(?i)' . getexts() . '$/',$file); 
  4. //first character cannot be . : ? - subsequent characters can't be a : ? 
  5. //then a . character and must end with one of your extentions 
  6. //getexts() can be replaced with your extentions pattern 
  7. function getexts(){ 
  8. //list acceptable file extensions here 
  9. return '(app|avi|doc|docx|exe|ico|mid|midi|mov|mp3| 
  10. mpg|mpeg|pdf|psd|qt|ra|ram|rm|rtf|txt|wav|word|xls)'; 
  11. echo isfile('/Users/YourUserName/Sites/index.html'); 
  12. ?> 

實例三:

  1. <?php 
  2. function deletefolder($path
  3. if ($handle=opendir($path)) 
  4. while (false!==($file=readdir($handle))) 
  5. if ($file<>"." AND $file<>".."
  6. if (is_file($path.'/'.$file)) 
  7. @unlink($path.'/'.$file); 
  8. if (is_dir($path.'/'.$file)) 
  9. deletefolder($path.'/'.$file); 
  10. @rmdir($path.'/'.$file); 
  11. ?> 

此函數將刪除所有文件與文件夾。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 获嘉县| 黑龙江省| 梨树县| 石柱| 怀化市| 阳新县| 荥阳市| 大庆市| 麦盖提县| 年辖:市辖区| 安达市| 金坛市| 许昌市| 吴旗县| 河南省| 大庆市| 瓦房店市| 忻州市| 新宁县| 云南省| 黄冈市| 义乌市| 介休市| 屯昌县| 武平县| 杭锦后旗| 平乐县| 大城县| 芮城县| 淄博市| 柞水县| 昭觉县| 天峻县| 磐石市| 普陀区| 手游| 清水县| 普安县| 镇远县| 依兰县| 永州市|