tottijohn Posted July 19, 2007 Share Posted July 19, 2007 $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 https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/ Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 Umm use a / to signify $dir as a directory $fullfile = $dir . "/" . $file; Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301936 Share on other sites More sharing options...
tottijohn Posted July 19, 2007 Author Share Posted July 19, 2007 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 https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301940 Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 u sure u have the permission in the dir..... Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301954 Share on other sites More sharing options...
tottijohn Posted July 19, 2007 Author Share Posted July 19, 2007 Care to elaborate abit more on setting permission? ??? Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301985 Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 Read about chmod. You will likely need a chmod value of at least 644. Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301986 Share on other sites More sharing options...
tottijohn Posted July 19, 2007 Author Share Posted July 19, 2007 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 https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-301998 Share on other sites More sharing options...
tottijohn Posted July 19, 2007 Author Share Posted July 19, 2007 I'm still stuck at this, anyone? :-\ Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-302061 Share on other sites More sharing options...
DeadEvil Posted July 19, 2007 Share Posted July 19, 2007 $dh = "dh_dir""; $dir = 'matchreports/'; if ($handle = opendir($dh)) { while (false !== ($file = readdir($dh))) { $fullfile = $dir ."/". $file; } $subtotal[] = file_get_contents($fullfile); print_r($subtotal); Link to comment https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-302076 Share on other sites More sharing options...
tottijohn Posted July 19, 2007 Author Share Posted July 19, 2007 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 https://forums.phpfreaks.com/topic/60693-help-with-file_get_contents-from-files-in-a-folder/#findComment-302085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.