I try to read all *.txt
files from a folder and write all content from each file into another txt file. But somehow it only writes one line into the txt file.
I tried with fwrite()
and file_put_contents()
, neither worked.
Here is my code:
<?php
$dh = opendir('/Applications/XAMPP/xamppfiles/htdocs/test/');
while($file = readdir($dh)) {
$contents = file_get_contents('/Applications/XAMPP/xamppfiles/htdocs/test/' . $file);
$dc = array($contents);
}
file_put_contents('content.txt', $dc);
?>