Connecting Tech Pros Worldwide Forums | Help | Site Map

Saving a file and showing file information.

houghi
Guest
 
Posts: n/a
#1: Nov 16 '08
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
--
Quote:
> 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" <

Jerry Stuckle
Guest
 
Posts: n/a
#2: Nov 16 '08

re: Saving a file and showing file information.


houghi wrote:
Quote:
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.
jstucklex@attglobal.net
==================
houghi
Guest
 
Posts: n/a
#3: Nov 16 '08

re: Saving a file and showing file information.


Jerry Stuckle wrote:
Quote:
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. :-(
Quote:
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
--
Quote:
> 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" <
Closed Thread