嘿家伙, 我在这里误解了什么?php directoryIterator问题 - 错误的路径?
$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 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
任何想法什么不顺心吗?
谢谢,这是有道理的。但它不起作用!如果我尝试你的确切代码$ dir只是一个“。”。点!没有路径在那里。没有错误被抛出。如果我回显'get_template_directory()。 '/ images/headers /''它可以正常工作,但是DirectoryIterator不会因为某种原因获取该值! – matt 2011-04-26 16:14:27
由DirectoryIterator构造函数返回的变量是DirectoryIterator对象,您将无法将其回显到屏幕。查看DirectoryIterator文档以获得更多关于如何使用它的信息http://us.php.net/manual/en/class.directoryiterator.php – jordanstephens 2011-04-26 19:25:35