【发布时间】:2019-07-15 09:32:58
【问题描述】:
您好,我正在使用 Wordpress 自定义主题,并且我想在页脚中显示从文件夹中选择的一系列随机图像。现在我的路径设置正确,并且路径的输出是正确的。然后我在<img> 标签中插入路径,它只显示损坏的图像图标。
当我检查时,图像路径是正确的并且图像名称在那里。但是,当我单击检查元素框内的图像链接查看它时,我得到一个拒绝访问!我试图显示图像的选项卡上出现错误 403。我现在对此进行了广泛的研究,并尝试了许多不同的方法。
有一次我尝试在httpd-vhosts.conf 和httpd-xampp.conf 中将Xampp 设置更改为allow all。这些都没有奏效。然后我开始怀疑这是否可能是一个 WordPress 问题,但我不确定如何解决这个问题,尽管我进行了所有研究。
这是我的代码的 sn-p
$path = dirname(__DIR__, 2) . '/uploads/footer-img/';
//this outputs pathname of C:\xampp7\htdocs\project\wp-content/uploads/footer-img/
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getBasename() . "\n";
echo $fileinfo->getBasename('.jpg') . "\n";
$r = $path . $fileinfo->getBasename();
//this below outputs my directory with the image.jpg name
echo $r;
//this outputs broken image icons
echo '<img src="' . $r . '"/>';
}
}
【问题讨论】:
-
开头那句话让我想起了random.cat
-
如果图像未显示,则路径不正确,要么未正确生成,要么图像完全无法显示。您可以手动构建 URL 并在浏览器中打开图像吗?一旦你得到这个工作,与你为它生成的内容进行比较。
-
你能举一个输出
$r的例子吗? -
@RamRaider 我的输出是
C:\xampp7\htdocs\project\wp-content/uploads/footer-img/ -
@Rarst 我尝试使用该 URL,但不断收到错误
Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct(http://localhost:7777/site/wp-content/uploads/footer-img/): failed to open dir: not implemented。我的 URL 输出是http://localhost:7777/site/wp-content/uploads/footer-img/
标签: php wordpress foreach xampp