Jump to content

Server Error! (Cannot modify header information)


danscreations

Recommended Posts

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:8) 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">';
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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" ?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.