下面的代码会检查我们是否在COURSES_DIR
中,我已在其他地方定义过。
if(dirname($_SERVER['PHP_SELF']) == COURSES_DIR)
如何修改代码以适用于COURSES_DIR
以下的子目录?例如,COURSES_DIR/sub/dir
。
答案 0 :(得分:0)
If you want to check if the running script is in a subfolder of what's defined in COURSES_DIR
, I would check if the current dirname
path string begins with COURSES_DIR
. Something along the lines of:
strpos(dirname($_SERVER['PHP_SELF']), COURSES_DIR) == 0
答案 1 :(得分:-1)
opendir()
和readdir
获取给定目录中的所有子目录; is_dir()
来识别文件是否是目录; $_SERVER['PHP_SELF']
;