Php 将if-else语句基于服务器上的图像来自哪个文件夹?
我使用php打开并列出文件夹中的文件,但我想以某种方式将其转换为if-else语句,这样,如果它来自“暗”背景文件夹,将显示白色徽标,如果它来自“亮”背景文件夹,将显示黑色徽标Php 将if-else语句基于服务器上的图像来自哪个文件夹?,php,wordpress,if-statement,background,graphical-logo,Php,Wordpress,If Statement,Background,Graphical Logo,我使用php打开并列出文件夹中的文件,但我想以某种方式将其转换为if-else语句,这样,如果它来自“暗”背景文件夹,将显示白色徽标,如果它来自“亮”背景文件夹,将显示黑色徽标 <?php //path to directory to open $directory = "backgrounds/dark"; $dir_handle = @opendir($directory) or die("Unable to open folder"); while(false !== ($file
<?php
//path to directory to open
$directory = "backgrounds/dark";
$dir_handle = @opendir($directory) or die("Unable to open folder");
while(false !== ($file = readdir($dir_handle)))
{
if($file != '.' && $file != '..')
{
echo "{image : 'http://occa-art.com/backgrounds/dark/".$file."'}, ";
}
}
closedir($dir_handle);
?>
徽标是黑暗和光明文件夹中的文件吗?但是如果您将目录设置为“黑色”,如何将其打开为“光明”@SLACEDIAMOND背景图像将分为黑暗和光明文件夹。徽标将存储在general images文件夹中。但如果有必要,这种情况可能会发生变化。@NicolaPeluchetti目前我正在使用相同的代码重复两次,将“暗”替换为“亮”,但除此之外,它完全相同,所以我没有发布它。对不起,如果这让人困惑的话。
<?php
$doc = new DOMDocument();
$doc->loadHTML($htmlAsString);
$xpath = new DOMXPath($doc);
$nodeList = $xpath->query('//img[@class="bg"]/@src');
for ($i = 0; $i < $nodeList->length; $i++) {
# Xpath query for attributes gives a NodeList containing DOMAttr objects.
# http://php.net/manual/en/class.domattr.php
echo $nodeList->item($i)->value . "<br/>\n";
}
$bg_url = $nodeList->item($i)->value; // not sure about this?
$parent = dirname("$bg_url");
if ($parent == 'dark') { ?>
<img src="<?php bloginfo('template_url'); ?>/images/OCCAIndexHeaderwhite.png" alt="OCCA logo" />
<?php } else { ?>
<img src="<?php bloginfo('template_url'); ?>/images/OCCAIndexHeaderblack.png" alt="OCCA logo" />
<?php } ?>