大家好,我有什么误解吗?
$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:
[26-Apr-2011] PHP致命错误:未捕获的异常'RuntimeException'与消息"DirectoryIterator: __construct (http://myblog.com/wp-content/themes/mytheme/images/headers/)(directoryiterator.——构造):打开目录失败:未实现在/用户/名字/根/myblog.com/wp-content/themes/mytheme/inc/header-image.php: 3堆栈跟踪:
<标题> 0/用户/名字/根/myblog.com/wp-content/themes/mytheme/inc/header-image.php (3):DirectoryIterator -> __construct (http://oberperf..。)
<标题> 1/用户/名字/根/myblog.com/wp-content/themes/mytheme/header.php (69):包括('/用户/名字…')
<标题> 2/用户/名字/根/myblog.com/wp-includes/theme.php (1112):require_once('/用户/名字…')
<标题> 3/用户/名字/根/myblog.com/wp-includes/theme.php (1088):load_template("/用户/的名字……"真正的)
<标题> 4/用户/名字/根/myblog.com/wp-includes/general-template.php (34):locate_template(数组,true)
5/Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php
第3行
标题>标题>标题>标题>标题>
你知道这里出了什么问题吗?
看起来您传递的是URL而不是路径:
DirectoryIterator->__construct('http://oberperf...')
您应该将目录的完整本地路径名传递给构造函数。
我很确定路径必须是文档根目录的绝对路径,而不是URL。
尝试get_template_directory()
代替:
$dir = new DirectoryIterator( get_template_directory() . '/images/headers/');
echo $dir;