php 目录迭代器问题 - 路径错误?
嘿伙计们, 我在这里误解了什么?
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在传递 URL 而不是路径:
您应该将目录的完整本地路径名传递给构造函数。
Looks like you're passing a URL instead of a path:
You should pass the full local path name of the directory to the constructor.
我非常确定该路径必须是来自文档根的绝对路径,而不是 URL。
尝试使用
get_template_directory()
代替:I'm pretty sure that the path must be absolute from the document root, not a URL.
Try
get_template_directory()
instead: