Page 1 of 1

[SOLVED] On successful upload goto new page automatically

Posted: Wed Jun 23, 2004 2:02 pm
by Cateyes
Ok I would like this page I am working on to automatically goto the next page once the upload is successful I have the command in right now that says upload successful and amunsure how to tell it to execute to goto the next page. here is the code.

Code: Select all

<?php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><basefont face="Verdana" size="2">
</head>
<body background="images/covbckgrnd.jpg">
<p><font color=blue size=2>
  <!-- <font face=verdana size=2 color =blue> Web Editor v 2.0</font> -->
  <font face=verdana size=3 color =#CC6600> Select the file you wish
  to upload</font>
  <?php
set_time_limit(0);
$numoffile = 1; 
// Fix path of your file to be uploaded
$file_dir = "Files/cod/"; // folder name for uploaded file
if ($_POST) { 
for ($i=0;$i<$numoffile;$i++) { 
if (trim($_FILES['myfiles']['name'][$i])!="") { 
$newfile = $file_dir.$_FILES['myfiles']['name'][$i]; 
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);  
} 
} 
} 
if (isset($i)&&$i>0) print "<br>Object has been uploaded.<br>"; 
print "<form method='post' enctype='multipart/form-data'>"; 
for($i=0;$i<$numoffile;$i++) { 
print "<input type='file' name='myfiles[]' size='30'><br>"; 
} 
print "<br><input type='submit' name='action' value='Copy Files'>"; 
print "</form>"; 
?>
   
</font>
</p>
<a href="testrec.php?recordID=<?php echo $newfile; ?>"><img src="images/adduser.jpg" width="175" height="46" border="0"></a>
</body>
</html>
?>

Basically I would like to get rid of the last 5 lines of code and change this line in the code

Code: Select all

<?php
if (isset($i)&&$i>0) print "<br>Object has been uploaded.<br>"; 
?>
by taking out Object has been uploaded to with this code to load the page testrec.php?recordID=<?php echo $newfile; ?>"
I hope this makes sense.

Posted: Wed Jun 23, 2004 2:05 pm
by markl999

Code: Select all

if (isset($i)&&$i>0){
    header("Location: testrec.php?recordID=".$newfile);
    exit;
}
But for this to work you'll have to move any output (all that html) down below it as you can't send a header after output has been sent (unless you want to use output buffering) .. or use an html meta-refresh ... the choice is yours :o

Posted: Wed Jun 23, 2004 2:15 pm
by Cateyes
OK here is the new code

Code: Select all

<?php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><basefont face="Verdana" size="2">
</head>
<body background="images/covbckgrnd.jpg">
<p><font color=blue size=2>
  <!-- <font face=verdana size=2 color =blue> Web Editor v 2.0</font> -->
  <font face=verdana size=3 color =#CC6600> Select the file you wish
  to upload</font>
<?php
set_time_limit(0);
$numoffile = 1; 
// Fix path of your file to be uploaded
$file_dir = "Files/cod/"; // folder name for uploaded file
if ($_POST) { 
for ($i=0;$i<$numoffile;$i++) { 
if (trim($_FILES['myfiles']['name'][$i])!="") { 
$newfile = $file_dir.$_FILES['myfiles']['name'][$i]; 
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);  
} 
} 
} 
if (isset($i)&&$i>0){ 
    header("Location: testrec.php?recordID=".$newfile); 
    exit; 
}  
print "<form method='post' enctype='multipart/form-data'>"; 
for($i=0;$i<$numoffile;$i++) { 
print "<input type='file' name='myfiles[]' size='30'><br>"; 
} 
print "<br><input type='submit' name='action' value='Copy Files'>"; 
print "</form>"; 
?>
</body>
</html>
?>
And this is the error the page displays

Code: Select all

Select the file you wish to upload 
Warning: Cannot modify header information - headers already sent by (output started at C:\My WebSite\testupload.php:10) in C:\My WebSite\testupload.php on line 24
This has to be an easy fix but I just can't see it but it does upload the file sucessfully

Posted: Wed Jun 23, 2004 2:18 pm
by feyd

Posted: Wed Jun 23, 2004 2:21 pm
by pickle
markl999 wrote: But for this to work you'll have to move any output (all that html) down below it as you can't send a header after output has been sent
Basically, set up your page like this

Code: Select all

<?php
if(isset($_POST))
{
   //check uploaded file
   if($uploaded_file_is_ok)
  {
      header("Location: some_other_page.php");
  }
}

//display HTML here

?>

Posted: Wed Jun 23, 2004 2:39 pm
by Cateyes
OK got it working never even thought that the html above could be the problem here is a sample of the working code if anyone is interested.

Code: Select all

<?php
<?php
set_time_limit(0);
$numoffile = 1;
// Fix path of your file to be uploaded
$file_dir = "Files/cod/"; // folder name for uploaded file
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
}
}
}
if (isset($i)&&$i>0){
	header("Location: testrec.php?recordID=".$newfile); 
    exit;
}
print "<form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$numoffile;$i++) {
print "<input type='file' name='myfiles[]' size='30'><br>";
}
print "<br><input type='submit' name='action' value='Copy Files'>";
print "</form>";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><basefont face="Verdana" size="2">
</head>
<body background="images/covbckgrnd.jpg">
<p><font color=blue size=2>
  <!-- <font face=verdana size=2 color =blue> Web Editor v 2.0</font> -->
  <font face=verdana size=3 color =#CC6600> Select the file you wish
  to upload</font></font>
</body>
</html>

?>
Again thanks for all the quick replies.