Jump to content

Help with file_get_contents from files in a folder


tottijohn

Recommended Posts

$dir = 'matchreports';
$dh = opendir($dir);
             while (($file = readdir($dh)) !== false){
        $fullfile = $dir . $file;
        $subtotal[] = file_get_contents($fullfile);

 

I am getting this msg "Warning: file_get_contents(matchreports010407.php) [function.file-get-contents]: failed to open stream: No such file or directory"

 

010407.php is one of the files i need to retrieve the contents from, including others from the folder. Pardon me cause i am relatively new to PHP, thanks.

That solved the error, but now another arises;

 

"file_get_contents(matchreports/.) [function.file-get-contents]: failed to open stream: Permission denied"

 

&

 

"file_get_contents(matchreports/..) [function.file-get-contents]: failed to open stream: Permission denied"

 

I am trying to get the contents from the files, count the keywords before echoing out

Thanks, i did read up on chmod. Guess the problem is i am testing it on a windows platform using WAMP5.

 

			$dir = 'matchreports';
		$dh = opendir($dir);

   while (($file = readdir($dh)) !== false){
   $fullfile = $dir. "/" . $file;
   $subtotal[] = file_get_contents($fullfile);
}
  	echo "$subtotal";

 

I am actually getting "Array" as the result instead of the contents from all the files in the folder. Am i missing out something?

Thanks, guess i am on the right track.

					$dir = 'matchreports';
					$dh = opendir($dir);
						while (($file = readdir($dh)) !== false){
					$fullfile = $dir ."/". $file;
					$subtotal[] = file_get_contents($fullfile);
					}
					print_r($subtotal);
	                                //added this for my viewing purpose only

					$keyword = substr_count($subtotal,'earth');
					echo "$keyword";

 

Still, it returns 0 despite having the word earth appearing multiple times in each file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.