0

Im making a script to create a tempoary text file to download and redirect back to a page,but im having the issue that everything after the header information is sent goes into the text file upon download.

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();

header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
Hello, world.
<script>

window.location.href="/usercp/monitorproducts.php";

</script>
<?



?>

as you can see the javascript code goes into the text file due to the header.. what can i do?

thank you.

2

2 Answers 2

2

Once you use "header" to indicate that you are sending back a file, the client will treat it as such.

The web server is sending back a response header that is telling the browser it's about to receive a file.

0

wow i found a solution that works!

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();
header( "refresh:5;url=/usercp/monitorproducts.php" );
header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
hello world

this redirects immoderately after downloading file,this worked randomly! the delay is nessecary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.