468,791 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,791 developers. It's quick & easy.

Saving a file and showing file information.

I am trying to do two things at a time. I want to give the user the
opportunity to save a file and at the same time see new information on
the screen.

I can do it seperately, but not together. What I have is the following:

@ob_end_clean();
$SHOW = "1";
if ($SHOW == 1) {
// Show all the info on a page
$TEXT = $TEXT."<pre>".$LINE."</pre>"; // $TEXT = website data
// $LINE = new content
include("../main_text2.inc"); // HTML Layout
} else {
// Save the file
$length = strlen($LINE);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'.itn"');
print $LINE; // $LINE = new content
}

When I change the "1" into a "0" it will save the file. So sperately
this works, but together it doesn't. When I try it together I get the
error with each header: <b>Warning</b>: Cannot modify header
information - headers already sent by (output started at header.inc:3)
in <b>test02.php</bon line <b>133</b><br />

header.inc (which is an include in main_text2.inc) cointains:
<html>
<head>
<title><?php print $TITLE; ?></title>
<link rel="stylesheet" title="Shell (Default)" type="text/css"
href="/style.css" media="screen">
<link rel="alternate stylesheet" title="Newer" type="text/css"
href="/new_style.css" media="screen">
</head>
<body>
<div id="page">
So what can I do do first show the info and when the page is loaded give
the visitor the ability to save the file?

houghi
--
> Beware of he who would deny you access to information, <
for in his heart he dreams himself your master. <
Commissioner Pravin Lal: "U.N. Declaration of Rights" <
Nov 16 '08 #1
2 1512
houghi wrote:
I am trying to do two things at a time. I want to give the user the
opportunity to save a file and at the same time see new information on
the screen.

I can do it seperately, but not together. What I have is the following:

@ob_end_clean();
$SHOW = "1";
if ($SHOW == 1) {
// Show all the info on a page
$TEXT = $TEXT."<pre>".$LINE."</pre>"; // $TEXT = website data
// $LINE = new content
include("../main_text2.inc"); // HTML Layout
} else {
// Save the file
$length = strlen($LINE);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'.itn"');
print $LINE; // $LINE = new content
}

When I change the "1" into a "0" it will save the file. So sperately
this works, but together it doesn't. When I try it together I get the
error with each header: <b>Warning</b>: Cannot modify header
information - headers already sent by (output started at header.inc:3)
in <b>test02.php</bon line <b>133</b><br />

header.inc (which is an include in main_text2.inc) cointains:
<html>
<head>
<title><?php print $TITLE; ?></title>
<link rel="stylesheet" title="Shell (Default)" type="text/css"
href="/style.css" media="screen">
<link rel="alternate stylesheet" title="Newer" type="text/css"
href="/new_style.css" media="screen">
</head>
<body>
<div id="page">
So what can I do do first show the info and when the page is loaded give
the visitor the ability to save the file?

houghi

Any particular page request from the browser can only have one content
type and content disposition. You're trying to get two different ones
for the same file, which is not allowed.

To do what you want, you need the browser to make two different requests
and load two different files. Try alt.html to find out how to do it
from the html end, and put your code to generate the data to be saved in
another file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 16 '08 #2
Jerry Stuckle wrote:
Any particular page request from the browser can only have one content
type and content disposition. You're trying to get two different ones
for the same file, which is not allowed.
OK. :-(
To do what you want, you need the browser to make two different requests
and load two different files. Try alt.html to find out how to do it
from the html end, and put your code to generate the data to be saved in
another file.
Bummer, but thanks. Atr least I now do not loose any extra time looking
for a solution that isn't there.

houghi
--
> Beware of he who would deny you access to information, <
for in his heart he dreams himself your master. <
Commissioner Pravin Lal: "U.N. Declaration of Rights" <
Nov 16 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by G-Factor | last post: by
1 post views Thread by Stephajn Craig | last post: by
1 post views Thread by M Keeton | last post: by
5 posts views Thread by TheGanjaMan | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.