Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
How to force download after file_put_contents in CakePHP?

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);
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!