mactron Posted May 10, 2021 Share Posted May 10, 2021 I would like to write all files from specific folder into .txt file. The output working just fine, but I'm getting only one file saved into my txt file. Any idea? Thanks! $fileList = glob('C:\users\John\Documents\*pdf'); foreach($fileList as $filename){ if(is_file($filename)){ echo $filename, '<br>'; $save_files = fopen("list.txt", "w"); fwrite($save_files,$filename); fclose($save_files); } } Quote Link to comment https://forums.phpfreaks.com/topic/312659-how-to-save-results-from-foreach-into-txt-file/ Share on other sites More sharing options...
Solution Barand Posted May 10, 2021 Solution Share Posted May 10, 2021 Open the txt file before the loop and close it after the loop. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312659-how-to-save-results-from-foreach-into-txt-file/#findComment-1586444 Share on other sites More sharing options...
mactron Posted May 10, 2021 Author Share Posted May 10, 2021 Ohhh thank you Quote Link to comment https://forums.phpfreaks.com/topic/312659-how-to-save-results-from-foreach-into-txt-file/#findComment-1586445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.