Reputation: 452
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.
Upvotes: 0
Views: 414
Reputation: 452
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
Upvotes: 0
Reputation: 1220
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.
Upvotes: 2