i have PHP code that read multiple TXT files and allow the user to make a search on a specified string, and after the system read all text files and based on the user input the system will display the files name that contain the user request.
the problem is that when i run the code the webpage display :
Warning: fopen() expects parameter 1 to be a valid path, array given in C:\xampp\htdocs\readfiletest\index.php on line 11
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\readfiletest\index.php on line 64
where the error in my code and how to fix it ?
code:
<?php
//path to directory
$directory = $_SERVER['DOCUMENT_ROOT']."/readfiletest/";
$txts= glob($directory. "*.txt") or DIE("Unable to open $directory");
$myFileLink = fopen($txts, 'r');
$line = 1;
if(isset($_POST["search"]))
{
$search =$_POST['name'];
while(!feof($myFileLink))
{
$myFileContents = fgets($myFileLink);
if( preg_match_all('/('.preg_quote($search,'/').')/i', $myFileContents, $matches))
{
foreach($matches[1] as $match)
{
echo "Found $match on Line $line";
}
}
++$line;
}
}
fclose($myFileLink);
?>
<html>
<head>
</head>
<meta http-equiv="Content-Language" content="ar-sa">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<form action="index.php" method="post">
<p>enter your string <input type ="text" id = "idName" name="name" /></p>
<p><input type ="Submit" name ="search" value= "Search" /></p>
</form>
</body>
</html>