0

Hi,
I am a novice programmer at PHP. I want to redirect my webpage to another webpage. The problem is that First I want to output a file as an attachment and then redirect the web page
I have used this code to output the attachment file

header("Content-Disposition: attachment; filename=$filename");
echo $out;

where

$out

is the text I want to write in my attachment file.
Now Since I have used echo here I cant use

header("location:");

to redirect my webpage. I have also tried to use ob_start() and ob_end_flush() but then my file wont be outputted as an attachment. What should I do?

Edited by gunjannigam: n/a

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by gunjannigam
0

You need to open your attachment in a new window, with javascript:

<script>
window.open("yourFileWithAttachment.php");
</script>

Then in the main window you can redirect to another page with header.

header("Location: newPage.php");
0

You need to open your attachment in a new window, with javascript:

<script>
window.open("yourFileWithAttachment.php");
</script>

Then in the main window you can redirect to another page with header.

header("Location: newPage.php");

Pardon me, If I am wrong but to use the JavaScript from my current php page I will have to echo it out from my php page and since I would have used echo will the header work??

0

Ok, will not work.
Try a HTML redirect:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.pageToRedirect.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
0

Ok, will not work.
Try a HTML redirect:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.pageToRedirect.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>

Ok,
I tried to did what u said but still i am facing problems
I have written

header("Content-Disposition: attachment; filename=$filename");
		echo $out;exit;

and then after closing php tag

<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=<?php $path = "http://" . $_SERVER['SERVER_NAME'] . 
		strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"))."export.php"; echo $path;?>></HEAD>
<BODY>
</BODY>
</HTML>

To redirect to my webpage

But instead of outputting the redirect information on my browser it is outputted on my file, and that too before my

$out

data.
What should I do to correct this

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.