PHP中有没有检查目录或文件夹是否存在的函数?

发布于 2024-08-16 06:03:18 字数 80 浏览 0 评论 0 原文

我想在上传文件之前检查目录是否存在。

如果该目录不存在,则返回 FALSE。

is_dir 可以完成这项工作吗?

I want to check if there is a directory exist or not before uploading a file.

If the directory does not exist return FALSE.

Does is_dir do the work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

近箐 2024-08-23 06:03:18

是的 is_dir() 是解决方案。你尝试过吗?

Yes is_dir() is the solution. Did you try it?

梦开始←不甜 2024-08-23 06:03:18

is_dir() 我们将检查第一个参数是否为目录,并且 is_file() 将检查第一个参数是否是文件。

如果目录/文件存在,它们都返回 true,如果不存在,则返回 false。

is_dir() well check if the first argument is a directory and is_file() will check if the first argument is a file.

They both return true if the dir/file exists, and false if not.

菩提树下叶撕阳。 2024-08-23 06:03:18

例如,如果您想检查“etc/data/images/”是否是一个目录,您可以使用:

$dir = "etc/data/images/";  //First specify the directory you want to check existence of.

    if(is_dir($dir)){ //The 'is_dir' function does the checking.

     echo "Yes, $dir is a directory.";

}else{//If 'is_dir' returns false, the following will be ran:

    echo 'No that is not a directory...';
}

For example, if you wanted to check that "etc/data/images/" is a directory you could use:

$dir = "etc/data/images/";  //First specify the directory you want to check existence of.

    if(is_dir($dir)){ //The 'is_dir' function does the checking.

     echo "Yes, $dir is a directory.";

}else{//If 'is_dir' returns false, the following will be ran:

    echo 'No that is not a directory...';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文