How can I download the content from the DB as .txt file and wrap it inside a folder name according to lang?
By the way I want to use zipArchive PHP.
This is my data after fetching
Array(
[0] => Array
(
[id] => 1
[file_name] => "alpha"
[content] => "alpha one"
[lang] => "ko"
)
[1] => Array
(
[id] => 2
[file_name] => "bravo"
[content] => "bravo two"
[lang] => "ko"
)
[2] => Array
(
[id] => 3
[file_name] => "charlie"
[content] => "charlie three"
[lang] => "tw"
)
)
[3] => Array
(
[id] => 4
[file_name] => "alpha"
[content] => "alpha two"
[lang] => "tw"
)
)
This should be the expected output inside zip file.
- filename.zip
- tw <- folder
- alpha.txt
* alpha one // content
* alpha two // content
- charlie.txt
* charlie three // content
- ko
- bravo.txt
* bravo two // content
And I used file_put_contents.
foreach ($data as $result) {
$content .= 'content "' . trim($result['content']) . '"' . "\n";
file_put_contents($result['file_name'], $content);
}