创建要下载的文件而无需下载到服务器PHP

What I'm trying to do is to generate a file and specify the content in there without actually saving and creating the file on the server.

<link rel="stylesheet" href="css/style.css" />
<?php
if(isset($_POST['download'])){
    header('Content-disposition: attachment; filename=testing.txt');
    header('Content-type: text/plain');
    echo 'Lorem Ipsum';
    exit();
}
echo 
'
<form method="POST" action="index.php">
<input type="submit" name="download" value="submit"/>
</form>
';
?>

The generated .txt file now contains content before <?php whic is <link rel="stylesheet" href="css/style.css" /> and also Lorem Ipsum, but I ONLY the want the content I specified which is just Lorem Ipsum

Header should come before anything is echoed.

<?php
if(isset($_POST['download'])){
    header('Content-disposition: attachment; filename=testing.txt');
    header('Content-type: text/plain');
    echo 'Lorem Ipsum';
    exit();
}
echo 
'
<link rel="stylesheet" href="css/style.css" />
<form method="POST" action="index.php.php">
<input type="submit" name="download" value="submit"/>
</form>
';
?>

To keep it in the same structure:

$data = '<link rel="stylesheet" href="css/style.css" />';

if(isset($_POST['download'])){
    header('Content-disposition: attachment; filename=testing.txt');
    header('Content-type: text/plain');
    echo 'Lorem Ipsum';
    exit();
}
$data .='
<form method="POST" action="index.php.php">
<input type="submit" name="download" value="submit"/>
</form>
';

echo $data;

I've created another file called createfile.php:

<?php
     header('Content-diposition: attachment; filename=testing.php');
     header('Content-type: text/plain');
     echo 'Lorem Ipsum';
?>

and in index.php

<link rel="stylesheet" href="css/style.css" />

<form action="createfile.php" method="POST">
    <input type="submit" name="submit" value="submit"/>
</form>

now it will only load things in createfile.php