600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > php查找txt文件是否有 php怎么查询txt文件是否存在

php查找txt文件是否有 php怎么查询txt文件是否存在

时间:2021-11-10 00:52:50

相关推荐

php查找txt文件是否有 php怎么查询txt文件是否存在

php查询txt文件是否存在的方法:首先创建一个PHP示例文件;然后定义需要查询的TXT文件路径;最后通过“if(file_exists($filename)) {...}”方式判断txt文件是否存在即可。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

file_exists — 检查文件或目录是否存在

说明file_exists ( string $filename ) : bool

检查文件或目录是否存在。

参数

filename

文件或目录的路径。

在 Windows 中要用 //computername/share/filename 或者 \\computername\share\filename 来检查网络中的共享文件。

返回值

如果由 filename 指定的文件或目录存在则返回 true,否则返回 false。

注意:This function will return false for symlinks pointing to non-existing files.

注意:The check is done using the real UID/GID instead of the effective one.

注意: 因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果。

【推荐学习:《PHP视频教程》】

范例

示例 #1 测试一个文件是否存在<?php

$filename = '/path/to/foo.txt';

if (file_exists($filename)) {

echo "The file $filename exists";

} else {

echo "The file $filename does not exist";

}

?>

错误/异常

失败时抛出E_WARNING警告。

注释

注意: 此函数的结果会被缓存。参见 clearstatcache() 以获得更多细节。

小技巧

自 PHP 5.0.0 起, 此函数也用于某些 URL 包装器。请参见 支持的协议和封装协议以获得支持 stat() 系列函数功能的包装器列表。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。