【发布时间】:2011-11-27 03:05:52
【问题描述】:
我收到以下警告:
Warning: file_get_contents(C:\xampp\htdocs\test/wp-content/themes/test\images) [function.file-get-contents]: failed to open stream: Permission denied in ..\plugins\theme-check\main.php on line 29
main.php 的第 29 行内容为:
$other[$filename] = file_get_contents( $filename );
这里是与 $files 相关的代码:
$files = listdir( $theme );
$files = array_merge( listdir( $parent ), $files );
if ( $files ) {
foreach( $files as $key => $filename ) {
if ( substr( $filename, -4 ) == '.php' ) {
$php[$filename] = php_strip_whitespace( $filename );
}
else if ( substr( $filename, -4 ) == '.css' ) {
$css[$filename] = file_get_contents( $filename );
}
else {
$other[$filename] = file_get_contents( $filename );
}
}
// run the checks
$failed = !run_themechecks($php, $css, $other);
据我了解,是权限错误。由于该文件似乎无法访问该文件夹。我在 Windows 7 上使用 XAMPP。我不知道如何更改 Windows 上的文件夹权限。
PS。请注意警告中的文件夹路径,它有\和/。
我不想关闭警告等,而是想修复警告。
【问题讨论】:
-
您是要对名为 images 的文件夹还是在名为 images 的文件夹内的文件上执行 file_get_contents 操作?
-
您需要找到创建 $filename 的行或传递给它的内容以从中获取内容。此信息将有助于找出问题所在
-
@James Williams 我刚刚添加了代码。请看一看。
-
如果 $filename 为空,那么您生成的
$other['filename']将只包含一个目录。你不能在目录上使用file_get_contents()。 -
@MarcB 谢谢。詹姆斯·威廉姆斯提供了帮助。