php 目录迭代器问题 - 路径错误?

发布于 2024-11-03 07:40:03 字数 1470 浏览 1 评论 0原文

嘿伙计们, 我在这里误解了什么?

$dir = get_bloginfo('template_url').'/images/headers/';
echo $dir;
//ouput: myblog.com/wp-content/themes/mytheme/images/headers



$dir = new DirectoryIterator(get_bloginfo('template_url').'/images/headers/');
echo $dir;
//output: nothing at all! blank page!

控制台输出 fatal_error:

[2011 年 4 月 26 日] PHP 致命错误: 未捕获的异常“RuntimeException” 有消息 'DirectoryIterator::__construct(http://myblog.com/wp-content/themes/mytheme/images/headers/) [目录迭代器.--构造]: 无法打开目录:未实施' 在 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php:3 堆栈跟踪:

0 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php(3):

DirectoryIterator->__construct('http://oberperf...')

1 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/header.php(69):

include('/Users/myname...')

2 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1112):

require_once('/Users/myname...')

3 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1088):

load_template('/用户/我的名字...', 正确)

4 /Users/myname/htdocs/myblog.com/wp-includes/general-template.php(34):

locate_template(数组,true)

5 /Users/myname 在 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php

第 3 行

知道这里出了什么问题吗?

hey guys,
what do I misunderstand here?

$dir = get_bloginfo('template_url').'/images/headers/';
echo $dir;
//ouput: myblog.com/wp-content/themes/mytheme/images/headers



$dir = new DirectoryIterator(get_bloginfo('template_url').'/images/headers/');
echo $dir;
//output: nothing at all! blank page!

the console puts out a fatal_error:

[26-Apr-2011] PHP Fatal error:
Uncaught exception 'RuntimeException'
with message
'DirectoryIterator::__construct(http://myblog.com/wp-content/themes/mytheme/images/headers/)
[directoryiterator.--construct]:
failed to open dir: not implemented'
in
/Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php:3
Stack trace:

0 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php(3):

DirectoryIterator->__construct('http://oberperf...')

1 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/header.php(69):

include('/Users/myname...')

2 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1112):

require_once('/Users/myname...')

3 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1088):

load_template('/Users/myname...',
true)

4 /Users/myname/htdocs/myblog.com/wp-includes/general-template.php(34):

locate_template(Array, true)

5 /Users/myname in /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php

on line 3

any idea what goes wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2024-11-10 07:40:03

看起来您正在传递 URL 而不是路径:

DirectoryIterator->__construct('http://oberperf...')

您应该将目录的完整本地路径名传递给构造函数。

Looks like you're passing a URL instead of a path:

DirectoryIterator->__construct('http://oberperf...')

You should pass the full local path name of the directory to the constructor.

停顿的约定 2024-11-10 07:40:03

我非常确定该路径必须是来自文档根的绝对路径,而不是 URL。

尝试使用 get_template_directory() 代替:

$dir = new DirectoryIterator( get_template_directory() . '/images/headers/');
echo $dir;

I'm pretty sure that the path must be absolute from the document root, not a URL.

Try get_template_directory() instead:

$dir = new DirectoryIterator( get_template_directory() . '/images/headers/');
echo $dir;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文