PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Cateyes
Forum Commoner
Posts: 63 Joined: Mon Jun 14, 2004 5:06 pm
Post
by Cateyes » Wed Jun 23, 2004 2:02 pm
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.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Jun 23, 2004 2:05 pm
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
Cateyes
Forum Commoner
Posts: 63 Joined: Mon Jun 14, 2004 5:06 pm
Post
by Cateyes » Wed Jun 23, 2004 2:15 pm
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
Last edited by
Cateyes on Wed Jun 23, 2004 2:18 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 23, 2004 2:18 pm
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 23, 2004 2:21 pm
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
?>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Cateyes
Forum Commoner
Posts: 63 Joined: Mon Jun 14, 2004 5:06 pm
Post
by Cateyes » Wed Jun 23, 2004 2:39 pm
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.