本文将介绍在 PHP 中检查文件是否存在的不同方法。 使用 file_exists() 函数检查 php 中是否存在文件 在 PHP 中我们有一个内置的函数来检查一个文件是否存在,这个函数是
本文将介绍在 PHP 中检查文件是否存在的不同方法。
file_exists()
函数检查 php 中是否存在文件
在 PHP 中我们有一个内置的函数来检查一个文件是否存在,这个函数是 file_exists()
。这个函数接受文件路径或名称作为参数,并检查给定文件是否存在。使用该函数的正确语法如下。
file_exists($path);
该函数只接受一个参数。它的详细参数如下。
变量 | 说明 |
---|---|
$path |
它是我们要检查的文件的路径。 |
如果文件存在于指定的目录中,函数返回 True
。下面的程序显示了我们使用 PHP file_exists()
函数来检查文件是否存在的方法。
<?php
$path = '/user/test/How to check if file exists in PHP.txt';
if (file_exists($path)) {
echo "The file $path exists";
} else {
echo "The file $path does not exist";
}
?>
输出:
The file /user/test/How to check if file exists in PHP.txt exists.
--结束END--
本文标题: PHP 中检查文件是否存在
本文链接: https://www.lsjlt.com/news/569086.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0