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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.