提前谢谢。
使用以下代码时出现此警告:
警告: file_get_contents(test.php)函数.file-get-contents:无法打开流:在so-n-so行的/path/index.php中没有这样的文件或目录。
这是我使用的代码,
<?php
// Scan directory for files
$dir = "path/";
$files = scandir($dir);
// Iterate through the list of files
foreach($files as $file)
{
// Determine info about the file
$parts = pathinfo($file);
// If the file extension == php
if ( $parts['extension'] === "php" )
{
// Read the contents of the file
$contents = file_get_contents($file);
// Find first occurrence of opening template tag
$from = strpos($contents, "{{{{{");
// Find first occurrence of ending template tag
$to = strpos($contents,"}}}}}");
// Pull out the unique name from between the template tags
$uniqueName = substr($contents, $from+5, $to);
// Print out the unique name
echo $uniqueName ."<br/>";
}
}
?>发布于 2012-01-13 07:07:29
错误消息指出找不到该文件。
这是因为scandir()只返回目录中文件的基本名称。它不包括目录名。您可以改用glob():
$files = glob("$dir/*.php");这将返回结果列表中的路径,还会使您的扩展检查变得多余。
https://stackoverflow.com/questions/8843649
复制相似问题