|
 |
asp_components thread: ASPUpload problem
Message #1 by "peter" <ph@t...> on Sun, 8 Oct 2000 21:32:20 +0100
|
|
The following code is for uploading files to a db using the ASPUpload
component...The code works fine but when I try to assign a value to a
Cookie or Response.Redirect I get the error
The HTTP headers are already written to the client browser. Any HTTP
header modifications must be made before writing page content.
Which I usually associate with not Buffering ...
Any help greatly appreciated
cheers peter
<%
Dim filename, rs
Set Upload = Server.CreateObject("Persits.Upload.1")
Count = Upload.SaveToMemory
ConnectStr = strConnect
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "Files", ConnectStr, 2, 3
Response.Write "<H2>Upload Report <BR><BR></H2>"
For Each File in Upload.Files
rs.AddNew
rs("file1").Value = File.Binary
rs("Filename").Value = File.ExtractFileName
filename = rs("Filename").Value
Response.Buffer = True 'offending code
Response.Clear = True 'with or without these lines
Response.Cookies("filename") = filename 'error line # here
rs.Update
Next
%>
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 9 Oct 2000 14:42:27 +1000
|
|
Look at your code.
You can't do:
Response.Cookies("filename")
after you have done
Response.Write "<H2>Upload Report <BR><BR></H2>"
You can't send HTTP header information (eg set cookies) after you have sent
data to the client. You need to turn on buffering before you have sent data
to the client so that the server will hold on to everything, and send it in
the correct order when it reaches Response.Flush or the end of the page.
In any case I consider it better practise to leave writing anything to the
client until after you've done all the header work (setting cookies,
response.redirect etc).
Also, Response.Write is a function call, so use ( ) (not necessary, but
desirable)
Response.Write("<h2>Upload Report<br><br></h2>" & vbCrLf)
Cheers
Ken
----- Original Message -----
From: "peter" <ph@t...>
To: "ASP components" <asp_components@p...>
Sent: Monday, October 09, 2000 2:47 PM
Subject: [asp_components] ASPUpload problem
> The following code is for uploading files to a db using the ASPUpload
> component...The code works fine but when I try to assign a value to a
> Cookie or Response.Redirect I get the error
>
> The HTTP headers are already written to the client browser. Any HTTP
> header modifications must be made before writing page content.
>
> Which I usually associate with not Buffering ...
>
> Any help greatly appreciated
>
> cheers peter
>
>
> <%
> Dim filename, rs
> Set Upload = Server.CreateObject("Persits.Upload.1")
> Count = Upload.SaveToMemory
>
> ConnectStr = strConnect
>
> Set rs = Server.CreateObject("adodb.recordset")
> rs.Open "Files", ConnectStr, 2, 3
> Response.Write "<H2>Upload Report <BR><BR></H2>"
> For Each File in Upload.Files
> rs.AddNew
> rs("file1").Value = File.Binary
> rs("Filename").Value = File.ExtractFileName
>
> filename = rs("Filename").Value
>
> Response.Buffer = True 'offending code
> Response.Clear = True 'with or without these lines
> Response.Cookies("filename") = filename 'error line # here
>
> rs.Update
> Next
>
> %>
Message #3 by "Michael A. Michalski" <mmcihalski@n...> on Sun, 8 Oct 2000 17:46:17 -0400
|
|
You have set Response.Buffer = True AFTER you have written your HTTP
headers. They get written with the Response.Write command issued a few
lines before.
Move Response.Buffer = True to the top of your file and you should be fine
<%
<-- Put Response.Buffer up here -->
Dim filename, rs
Set Upload = Server.CreateObject("Persits.Upload.1")
Count = Upload.SaveToMemory
ConnectStr = strConnect
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "Files", ConnectStr, 2, 3
Response.Write "<H2>Upload Report <BR><BR></H2>" <-- Headers get written
here
For Each File in Upload.Files
rs.AddNew
rs("file1").Value = File.Binary
rs("Filename").Value = File.ExtractFileName
filename = rs("Filename").Value
Response.Buffer = True 'offending code <-- Buffering begins here
Response.Clear = True 'with or without these lines
Response.Cookies("filename") = filename 'error line # here
rs.Update
Next
%>
----- Original Message -----
From: "peter" <ph@t...>
To: "ASP components" <asp_components@p...>
Sent: Monday, October 09, 2000 12:47 AM
Subject: [asp_components] ASPUpload problem
> The following code is for uploading files to a db using the ASPUpload
> component...The code works fine but when I try to assign a value to a
> Cookie or Response.Redirect I get the error
>
> The HTTP headers are already written to the client browser. Any HTTP
> header modifications must be made before writing page content.
>
> Which I usually associate with not Buffering ...
>
> Any help greatly appreciated
>
> cheers peter
>
>
> <%
> Dim filename, rs
> Set Upload = Server.CreateObject("Persits.Upload.1")
> Count = Upload.SaveToMemory
>
> ConnectStr = strConnect
>
> Set rs = Server.CreateObject("adodb.recordset")
> rs.Open "Files", ConnectStr, 2, 3
> Response.Write "<H2>Upload Report <BR><BR></H2>"
> For Each File in Upload.Files
> rs.AddNew
> rs("file1").Value = File.Binary
> rs("Filename").Value = File.ExtractFileName
>
> filename = rs("Filename").Value
>
> Response.Buffer = True 'offending code
> Response.Clear = True 'with or without these lines
> Response.Cookies("filename") = filename 'error line # here
>
> rs.Update
> Next
>
> %>
>
Message #4 by Imar Spaanjaars <Imar@S...> on Sun, 08 Oct 2000 23:50:38 +0200
|
|
Hi Peter,
You turn on buffering too late. It should be either turned on for the whole
application, or (when you use it at page level) you should turn it on
before you write any content to the browser.
Before you loop through the files, you do this:
Response.Write "<H2>Upload Report <BR><BR></H2>"
So content has been written to the browser, and buffering can no longer be
turned on. Also cookies can no longer be set. They are part of the HTTP
headers as well, and therefore need to be set before any content is written.
Move the H2 after the cookies part and all problems should be gone.
HtH
Imar
At 09:47 PM 10/8/2000 -0700, you wrote:
>The following code is for uploading files to a db using the ASPUpload
>component...The code works fine but when I try to assign a value to a
>Cookie or Response.Redirect I get the error
>
>The HTTP headers are already written to the client browser. Any HTTP
>header modifications must be made before writing page content.
>
>Which I usually associate with not Buffering ...
>
>Any help greatly appreciated
>
>cheers peter
>
>
><%
> Dim filename, rs
> Set Upload = Server.CreateObject("Persits.Upload.1")
> Count = Upload.SaveToMemory
>
> ConnectStr = strConnect
>
> Set rs = Server.CreateObject("adodb.recordset")
> rs.Open "Files", ConnectStr, 2, 3
> Response.Write "<H2>Upload Report <BR><BR></H2>"
> For Each File in Upload.Files
> rs.AddNew
> rs("file1").Value = File.Binary
> rs("Filename").Value = File.ExtractFileName
>
> filename = rs("Filename").Value
>
> Response.Buffer = True 'offending code
> Response.Clear = True 'with or without these lines
> Response.Cookies("filename") = filename 'error line # here
>
> rs.Update
> Next
>
>%>
Message #5 by baohuan@w... on Mon, 9 Oct 2000 10:08:24 +0100
|
|
Try to put <%Response.Buffer = True%>
in the beginning of the code.
e.g
<%@ Language=VBScript %>
<%Response.Buffer = True%>
Regards,
Baohuan
-----Original Message-----
From: peter [mailto:ph@t...]
Sent: 09 October 2000 05:47
To: ASP components
Subject: [asp_components] ASPUpload problem
The following code is for uploading files to a db using the ASPUpload
component...The code works fine but when I try to assign a value to a
Cookie or Response.Redirect I get the error
The HTTP headers are already written to the client browser. Any HTTP
header modifications must be made before writing page content.
Which I usually associate with not Buffering ...
Any help greatly appreciated
cheers peter
<%
Dim filename, rs
Set Upload = Server.CreateObject("Persits.Upload.1")
Count = Upload.SaveToMemory
ConnectStr = strConnect
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "Files", ConnectStr, 2, 3
Response.Write "<H2>Upload Report <BR><BR></H2>"
For Each File in Upload.Files
rs.AddNew
rs("file1").Value = File.Binary
rs("Filename").Value = File.ExtractFileName
filename = rs("Filename").Value
Response.Buffer = True 'offending code
Response.Clear = True 'with or without these lines
Response.Cookies("filename") = filename 'error line # here
rs.Update
Next
%>
|
|
 |