-1
我现在面临的问题与此代码:无法读取文件中的PHP
<?php
$files = scandir("D:/Dummy");
foreach($files as $file) {
$filenam = $file;
$path_to_file = $filenam;
$file_contents = file_get_contents($path_to_file);
echo "Hello ".$filenam;
$printFileName="";
if(strpos("9222339940", $file_contents) === false)
{
$printFileName=$filenam." ";
}
}
echo $printFileName;
?>
基本上,我写了这个代码进行扫描目录,并从每个文件中的所有文件,我需要替换手机号码。但由于某种原因,我无法运行脚本。它抛出错误:
file_get_contents(name of the file) failed to open stream. No such file or directory error.
那么为了帮助你解决你的“出于某种原因”的问题,首先检查你的$文件是否有用。当你分配了var_dump($ files)后,你看到了什么?他们都是文件或文件和文件夹。 php.net怎么说scandir? – TimBrownlaw