danscreations Posted June 5, 2007 Share Posted June 5, 2007 Made a very simple upload script that also displays the contents of the directory it uploads to. Nothing complicated. However, not sure what kind of server I used to test it on but the final server I just moved it to which I know is LINUX is giving me the following error (which the tested server works perfect): "Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/a/n/cangirls/html/images/index.php: in /home/content/c/a/n/cangirls/html/images/index.php on line 20" The Script: <?php if (isset($_POST['submitBtn'])){ if ($_POST['uppass'] == "tada"){ if ($_FILES['upfile']['type'] == "image/pjpeg"){ $target_path = "/home/content/c/a/n/cangirls/html/images/"; $target_path = $target_path . basename( $_FILES['upfile']['name']); move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path); header("location: index.php?message=uploaded"); } else { header("location: index.php?message=error"); } } else{ header("location: index.php?message=password"); } } else { echo '<form enctype="multipart/form-data" action="index.php" method="POST" name="fileForm">'; echo '<table border="0" cellpadding="0" cellspacing="0" width="340">'; echo '<tr>'; echo '<td colspan="2" height="10" width="340" bgcolor="#5F8FCD"><center><b><font color="#FFFFFF">Image Uploader</font></b><font size="2">'; if ($_GET['message'] == "uploaded"){ echo ' (File Uploaded Sucessfully)'; } else if ($_GET['message'] == "error"){ echo ' (Error! File type not allowed)'; } else if ($_GET['message'] == "password"){ echo ' (Password Incorrect)'; } else{ } echo '</font></center></td>'; echo '</tr>'; echo '<tr><td colspan="2" height="5"></td></tr>'; echo '<tr>'; echo '<td width="110" align="right"><b>File To Upload: </b></td>'; echo '<td width="230"><input name="upfile" type="file"></td>'; echo '</tr>'; echo '<tr>'; echo '<td width="110" align="right"><b>Password: </b></td>'; echo '<td width="230"><input name="uppass" type="password"></td>'; echo '</tr>'; echo '<tr>'; echo '<td width="110"> </td>'; echo '<td width="230"><input type="image" src="../admin/img/upload_file.jpg"></td>'; echo '</tr>'; echo '</table>'; echo '<input type="hidden" name="submitBtn" value="Upload File">'; echo '</form>'; echo '<table width="340">'; echo '<td height="10" width="340" bgcolor="#5F8FCD"><center><b><font color="#FFFFFF">Images Uploaded</font></b></center></td></tr>'; echo '<tr><td colspan="2" height="5"></td></tr>'; echo '</table>'; $file_dir = "/home/content/c/a/n/cangirls/html/images"; $dir = opendir($file_dir); while ($file=readdir($dir)) { if ($file != "." && $file != "..") { if ($file == "index.php"){ } else{ echo '<input type="text" size="40" value="'.$file.'"> || '; echo '<a href="'.$file.'" target="_blank">View File</a>'; echo '<br>'; } } } } echo '<hr width="340" color="#000000" size="1" align="left">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/ Share on other sites More sharing options...
taith Posted June 5, 2007 Share Posted June 5, 2007 after your header() redirects put "exit;" Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/#findComment-268439 Share on other sites More sharing options...
Yesideez Posted June 5, 2007 Share Posted June 5, 2007 I would change your "while" line to this: while (false!==($file=readdir($dir))) { Documented here: http://www.php.net/readdir Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/#findComment-268469 Share on other sites More sharing options...
danscreations Posted June 5, 2007 Author Share Posted June 5, 2007 Neither seemed to work...sorry I'm new to php. Sucks that it worked on one server perfectly and now not on this one. Little fustrated. Here is the script live...will only alow JPEG images and the password is tada http://www.thecancancompany.com/images/ Forgot to mention that the php writes everything fine just when the upload form field is submitted to the script itself the above message is displayed. Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/#findComment-268534 Share on other sites More sharing options...
trq Posted June 5, 2007 Share Posted June 5, 2007 Sucks that it worked on one server perfectly and now not on this one. More than likely only because error_reporting was switched off and now its on. You should always have error_reporting on when developing. Anyway... have you read this sticky at the top of this board which says "HEADER ERRORS - READ HERE BEFORE POSTING THEM" ? Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/#findComment-268541 Share on other sites More sharing options...
danscreations Posted June 5, 2007 Author Share Posted June 5, 2007 Well not sure if this is what I needed to do...but works now! <html> <head> <title>Image Uploader v1.0</title> <?php if (isset($_POST['submitBtn'])){ if ($_POST['uppass'] == "tada"){ if ($_FILES['upfile']['type'] == "image/pjpeg"){ $target_path = "/home/content/c/a/n/cangirls/html/images/"; $target_path = $target_path . basename( $_FILES['upfile']['name']); move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path); $message = "uploaded"; } else { $message = "error"; } } else{ $message = "password"; } } ?> </head> <body> <?php echo '<form enctype="multipart/form-data" action="index.php" method="POST" name="fileForm">'; echo '<table border="0" cellpadding="0" cellspacing="0" width="340">'; echo '<tr>'; echo '<td colspan="2" height="10" width="340" bgcolor="#5F8FCD"><center><b><font color="#FFFFFF">Image Uploader </font></b><font size="2">'; if ($message == "uploaded"){ echo ' (File Uploaded Sucessfully)'; } else if ($message == "error"){ echo ' (Error! File type not allowed)'; } else if ($message == "password"){ echo ' (Password Incorrect)'; } else{ } echo '</font></center></td>'; echo '</tr>'; echo '<tr><td colspan="2" height="5"></td></tr>'; echo '<tr>'; echo '<td width="110" align="right"><b>File To Upload: </b></td>'; echo '<td width="230"><input name="upfile" type="file"></td>'; echo '</tr>'; echo '<tr>'; echo '<td width="110" align="right"><b>Password: </b></td>'; echo '<td width="230"><input name="uppass" type="password"></td>'; echo '</tr>'; echo '<tr>'; echo '<td width="110"> </td>'; echo '<td width="230"><input type="image" src="../admin/img/upload_file.jpg"></td>'; echo '</tr>'; echo '</table>'; echo '<input type="hidden" name="submitBtn" value="Upload File">'; echo '</form>'; echo '<table width="340">'; echo '<td height="10" width="340" bgcolor="#5F8FCD"><center><b><font color="#FFFFFF">Images Uploaded</font></b></center></td></tr>'; echo '<tr><td colspan="2" height="5"></td></tr>'; echo '</table>'; $file_dir = "/home/content/c/a/n/cangirls/html/images"; $dir = opendir($file_dir); while (false!==($file=readdir($dir))) { if ($file != "." && $file != "..") { if ($file == "index.php"){ } else{ echo '<input type="text" size="40" value="'.$file.'"> || '; echo '<a href="'.$file.'" target="_blank">View File</a>'; echo '<br>'; } } } echo '<hr width="340" color="#000000" size="1" align="left">'; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/54295-server-error-cannot-modify-header-information/#findComment-268659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.