PHP中有没有检查目录或文件夹是否存在的函数?
我想在上传文件之前检查目录是否存在。
如果该目录不存在,则返回 FALSE。
is_dir 可以完成这项工作吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在上传文件之前检查目录是否存在。
如果该目录不存在,则返回 FALSE。
is_dir 可以完成这项工作吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
是的 is_dir() 是解决方案。你尝试过吗?
Yes is_dir() is the solution. Did you try it?
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.
例如,如果您想检查“etc/data/images/”是否是一个目录,您可以使用:
For example, if you wanted to check that "etc/data/images/" is a directory you could use: