dandan321 Posted July 27, 2007 Share Posted July 27, 2007 Hello, If anyone can help with this it would be greatly appreciated. I am trying to upload files to my server and then have the page redirect to another page, like a thankyou page or another page to where I can pass some variables. However when I run this script and I add ---- Header("Location: somepage.php"); ----- I get the following error PHP Warning: Cannot modify header information - headers already sent by (output started at C:\hshome\martinar\martinarts.org\test\test.php:3) in C:\hshome\martinar\martinarts.org\test\test.php on line 26 below is my code for both the html and the php form.htm <html> <head></head> <body> <form action="test.php" method="post" enctype="multipart/form-data"> <br><br> Choose a file to upload:<br> <input type="file" name="file"><br> <input type="submit" name="submit" value="submit"> <input type="hidden" name="something" value="yeah buddy!"> </form> </body> </html> ========================================= test.php <?php if ($HTTP_POST_VARS['submit']) { print_r($HTTP_POST_FILES); if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) { $error = "You did not upload a file!"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. } else { //a file was uploaded $maxfilesize=10240000000; if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) { $error = "file is too large"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. } else { if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") { $error = "This file type is not allowed"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. } else { //File has passed all validation, copy it to the final destination and remove the temporary file: copy($HTTP_POST_FILES['file']['tmp_name'],"/hshome/martinar/martinarts.org/test/files/".$HTTP_POST_FILES['file']['name']); unlink($HTTP_POST_FILES['file']['tmp_name']); print "File has been successfully uploaded!"; Header("Location: somepage.php"); exit; } } } } ?> thanks, Dan Link to comment https://forums.phpfreaks.com/topic/61958-solved-file-upload-with-redirect/ Share on other sites More sharing options...
teng84 Posted July 27, 2007 Share Posted July 27, 2007 you cant use header if you will echo something or even when you output html Link to comment https://forums.phpfreaks.com/topic/61958-solved-file-upload-with-redirect/#findComment-308525 Share on other sites More sharing options...
hitman6003 Posted July 27, 2007 Share Posted July 27, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Link to comment https://forums.phpfreaks.com/topic/61958-solved-file-upload-with-redirect/#findComment-308527 Share on other sites More sharing options...
dandan321 Posted July 27, 2007 Author Share Posted July 27, 2007 Thanks! It was a simple as commenting out the print lines thanks again Dan Link to comment https://forums.phpfreaks.com/topic/61958-solved-file-upload-with-redirect/#findComment-308534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.