Search code examples
phpfiletexton-the-fly

Is there a way to generate two different text files on the fly with php?


Thanks to this topic I'm able to generate one single text file and download it on the fly. But I would like to generate two separated text files. My code seems like this:

        $status = //math

        if(status)

           header("Content-type: text/plain");
           header("Content-Disposition: attachment; filename=config.txt");

 //...config text

 include 'test.php'; 

Test.php file:

<?php 

    $timeout = "time";

    header("Content-type: text/plain");
    header("Content-Disposition: attachment; filename=timout.xml");

    echo $timeout;
?>

the timeout.xml text is being included inside config.txt, generating only the timout.xml file to download. Is there a way to generate two separated text files to download on the fly?


Solution

  • You cant do it because HTTP doesnt support the downloading of multiple files in a single click..The best option would be zipping the files on the server and transfering it as said here.

    Or you can use javascript to on the link to request two request to the server and which lets you fetch the data from the single click as @deceze and @brian said in the comment