php:检查路径是否存在? [英] php: check if path exists?

查看:152
本文介绍了php:检查路径是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,嗯,
我用一个查询字符串设置一个路径变量。
检查路径(总是一个目录)是否存在是最简单的方法。

hey guys, i'm setting a path variable with a query-string. what's the easiest way to check if the path (always a directory) exists or not.

    if(isset($_GET['p'])) {
    define(PATH, $_GET['p']);

所以现在我喜欢mydomain.com?p=files/folder/sub,一切正常,我正在读取文件夹的内容。
然而我可以传递?p = shit /任何,我没有得到一个404或类似的东西。系统读取一个甚至不存在的文件夹。

so now i have like mydomain.com?p=files/folder/sub and everything works fine, i'm reading the contents of the folder. however i can pass along ?p=shit/whatever and i don't get a 404 or anything like that. the system reads a folder which does not even exist.

我甚至不需要404,但只想打印(不存在!)或类似的东西。

i don't even need a 404, but just want to print('does not exist!') or anything similar.

最好的方法是什么?
谢谢

what's the best method to do that? thank you

推荐答案

file_exists: http://php.net/manual/en/function.file-exists.php

file_exists: http://php.net/manual/en/function.file-exists.php

is_dir: http://php.net/manual/en/function.is -dir.php

这篇关于php:检查路径是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆