Jump to content

problem with php header


saco721

Recommended Posts

Hi,

 

I have a problem with php headers. Basically I have a script that opens a saveas dialog box for downloading files. It works fine. The problem is that when I add an addional header to open a new page after the download is complete, the dialog box stops appearing and it just loads the page. Here is the code:

 

<?PHP

header("Content-type: application/octet-stream");

header("Content-Length: ".filesize($filename));

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

header('Location: http://www.testdl.com');//dialog does not popup but loads new page when this header is added

 

$fp = fopen($filename, 'rb');

fpassthru($fp);

fclose($fp);

 

?>

Where am I going wrong?

 

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/125464-problem-with-php-header/
Share on other sites

Here's the code:

 

<!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.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
[/cdoe]

Hi,

 

I have tried the code you provided me with and it does load the new page but doesnt open the saveas dialog. Have I done it right?

 

here is the code:

 

<!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.redirect.com"></HEAD>

<BODY>

 

</BODY>

</HTML>

<?PHP

header("Content-type: application/octet-stream");

header("Content-Length: ".filesize($filename));

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

 

 

$fp = fopen($filename, 'rb');

fpassthru($fp);

fclose($fp);

 

?>

 

thanks for your time!

This won't work.... you can't echo HTML when you've declared the script as a stream and expect it to be parsed

 

You have to call the PHP script serving the file in a new window or a frame, and then redirect in the parent page.

Hi!,

 

thanks for the advice. I have created a page using an iframe :

 

<html>

<body>

<iframe src="filedownload.html"

width="40%" height="80"

align="right" border = "1">

</iframe>

</body>

</html>

 

filedownload is :

 

<html>

<head>

</head>

<body>

<a href="filedownload4.php?filename=filetodownload.txt">Download this text file</a>

</body>

</html>

 

filedownload4.php is :

 

<?PHP

 

header("Content-type: application/octet-stream");

header("Content-Length: ".filesize($filename));

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

 

 

$fp = fopen($filename, 'rb');

fpassthru($fp);

fclose($fp);

?>

 

what is the code to refresh the page and where does it go?

 

Sorry but I am new to php. Thanks very much!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.