php directoryIterator问题-路径错误?
嘿,伙计们, 我在这里误解了什么php directoryIterator问题-路径错误?,php,path,iterator,directory,Php,Path,Iterator,Directory,嘿,伙计们, 我在这里误解了什么 $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: no
$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!
控制台发出一个致命错误:
[26-Apr-2011]PHP致命错误:
未捕获异常“RuntimeException”
带着信息
'DirectoryIterator::\u构造(http://myblog.com/wp-content/themes/mytheme/images/headers/)
[目录迭代器。--构造]:
无法打开目录:未实现'
在里面
/Users/myname/htdocs/myblog.com/wp-content/themes/myteme/inc/header-image.php:3
堆栈跟踪:
0/Users/myname/htdocs/myblog.com/wp content/themes/myteme/inc/header image.php(3):
DirectoryIterator->\u构造('http://oberperf...")
1/Users/myname/htdocs/myblog.com/wp content/themes/myteme/header.php(69):
包括(“/Users/myname…”)
2/Users/myname/htdocs/myblog.com/wp includes/theme.php(1112):
需要_一次('/Users/myname…'))
3/Users/myname/htdocs/myblog.com/wp includes/theme.php(1088):
加载模板('/Users/myname…',
(对)
4/Users/myname/htdocs/myblog.com/wp includes/general template.php(34):
找到_模板(数组,真)
5/Users/myname in/Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php
在线3
知道这里出了什么问题吗?看起来您传递的是URL而不是路径:
DirectoryIterator->__construct('http://oberperf...')
您应该将目录的完整本地路径名传递给构造函数。我非常确定该路径必须是文档根的绝对路径,而不是URL 请尝试:
谢谢,这很有道理。但是它不起作用!如果我尝试你的确切代码$dir只保留一个“.”点!那里没有路。不会抛出任何错误。如果我回显
get_template_directory()。'/images/headers/'
它工作正常,但由于某些原因,DirectoryIterator不会接受该值!DirectoryIterator构造函数返回的变量是一个DirectoryIterator对象,您不能将其直接回显到屏幕上。查看DirectoryIterator文档,了解有关如何使用它的更多信息。好的,没错。但是,这也不起作用:$dir=newdirectoryinterator('/Users/myname/htdocs/myblog.com/wp content/themes/myteme/images/headers/');echo$dir代码>DirectoryIterator返回一个对象而不是字符串。您需要迭代它:foreach($diras$item){echo$item->getFilename();}
$dir = new DirectoryIterator( get_template_directory() . '/images/headers/');
echo $dir;