DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > PHP
Reload this Page Problem in Redirect To Another Page
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2008
Default Problem in Redirect To Another Page - 05-12-2008, 06:22 AM

i Have created a php file uploader page and i want redirect into the another page after the file uploder function..It was working fine to me but suddently a problem came to me that header already sent...
here am attaching my sample code ..plz give me a solution to overcome tis problem asps...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<**** **********="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" enctype="multipart/form-data" method="post" action="">
<table width="200" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#0066CC">
<tr>
<td><table width="275" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="218" align="center" bgcolor="#F4F4F4"><div align="left">Attachment</div></td>
<td width="43" align="center"><input name="image" type="file" id="image"></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" value="Upload">
</td>
</tr>
<tr>
<td colspan="2" align="center" class="style1">
<?php
if($_REQUEST["Submit"] == "Upload")
{

if ($_FILES["image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
}
else
{
if (file_exists("upload/" . $_FILES["image"]["name"]))
{
move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $_FILES["image"]["name"]);
echo "Your File has been uploaded: " . "upload/" . $_FILES["image"]["name"];
echo $_FILES["image"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $_FILES["image"]["name"]);
echo "Your File has been uploaded: " . "upload/" . $_FILES["image"]["name"];
}
}

$img="upload/" . $_FILES['image']['name'];
header('location:salesenquiry.asp?a=$img');
exit;

}
?>
</td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="javascript:;" class="style1" onClick="window.close();">[close window] </a></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>

plz give the answer asps.

the error msg to tis code is,,

Your file has been uploaded: API-CLEANING VALIDATION.pdf
Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\vhosts\appleintlgroup.com\httpdocs\news upload.php:10) in c:\Inetpub\vhosts\appleintlgroup.com\httpdocs\news upload.php on line 49
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2008
Default 05-19-2008, 12:16 PM

If everything was working fine and suddenly you had this problem - like you say, and if the file was recently edited maybe a unwanted character is at the start of the php file?

Try this.

Open your page in 'edit' the old dos editor or something similar check if a nonprintable character is displayed - remove that hopefully it will work.
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Join Date: Sep 2008
Default Re: Problem in Redirect To Another Page - 03-27-2009, 11:49 AM

The problem is that the headers were sent just before <!DOCTYPE (not because it is a doctype, but because it is the first bit of HMTL). The headers would also be sent if you called echo or print. The headers can only be sent once, so when you try to redefine them using header() later in your script, it results in an error.

The solution is to either place the php code containing header() before any HTML, or use output buffering (ob_start(), ob_end_flush(), etc.) to control when the headers are sent. You could use variables as an alternative to the output buffering functions.

In your case, the echo statements that come before header() will cause the same error, so either use output buffering or modify your control statements (if, else, etc.) so that echo will never happen before header().

After closer examination of your code, I'm a little confused about what you are trying to do by using header() to redirect to salesenquiry.asp. Based on the logic, this redirect will always happen when the form is submitted, regardless of whether there is an error with image file. In addition, an error or a confirmation will always be displayed when the form is submitted. So what does salesenquiry.asp do?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eclipse RCP Preference Page problem adiherzog Eclipse 0 12-03-2008 05:39 AM
Using the eclipse welcome page instead of a customized intro page alterswede Eclipse 0 11-11-2008 01:37 PM
Error 500 On DZONE home page richarddean Feedback 0 11-11-2008 10:45 AM
Permalinks to comments on 2nd page incorrect ahalsey Feedback 0 08-20-2008 05:23 PM
components in the page... herculean Eclipse 0 04-10-2008 06:33 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com