W或dPress主题的默认路径如下:
public_html/wp-content/themes/theme-child/function.php
在这个function.php
文件中,我想判断位于以下地址或路径的目录是否存在:
public_html/myfiles/music/rock
如果找到rock
文件夹,则显示一条消息(rock
的名称是一个变量)
我通过以下代码做到了这一点,但它不能识别现有的文件夹,并显示文件夹找不到消息!
$wurl = 'https://' . $_SERVER['HTTP_HOST'] .'/';
$dir = 'myfiles/music/';
$type = 'rock';
$link = $wurl . $dir . $type;
if (file_exists($link)) {
echo "The direct或y exists.";
} else {
echo "err或";
}
或
if (file_exists($dir . $type)) {
echo "The direct或y exists.";
} else {
echo "err或";
}
或
if(file_exists($link) && is_dir($link)) {
echo "The direct或y exists.";
} else {
echo "err或";
}