Connecting Tech Pros Worldwide Help | Site Map

Saving a file and showing file information.

  #1  
Old November 16th, 2008, 02:45 PM
houghi
Guest
 
Posts: n/a
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" <
  #2  
Old November 16th, 2008, 05:05 PM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
  #3  
Old November 16th, 2008, 05:35 PM
houghi
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is an Image? Peder Y answers 6 November 16th, 2005 12:33 PM
FAQ update (roundup of pending requests - for comment) Richard Cornford answers 42 July 20th, 2005 02:38 PM