...

View Full Version : Cannot modify header information - headers already sent



fallingintoZero
05-02-2006, 05:57 PM
I know this is covered in the FAQ section, but what it says causes the problem isn't occuring. And I checked older messages and none of them resolved this issue.

A fellow CF poster here really helped me out and created a PHP script for me that allows a user to upload a file to my site. When they upload the file, they have an option to select the directory, and depending on which directory they select, it e-mails a different person that is associated with that directory. But we are thrown through a loop tryin got figure out why i am getting this error when i go to test it out:

Warning: move_uploaded_file(): Moved: '/var/tmp/phpgGCU5h' to 'irvineup/upload test - irvine.txt' in /home/variable/public_html/upload/ftp.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /home/variable/public_html/upload/ftp.php:24) in /home/variable/public_html/upload/ftp.php on line 26

It works great on his server when he tested it... but i can't get it to work on mine for some reason. The folders are CHMOD to 777 like they should be. The file uploads correctly. The correct person is e-mailed. But I can't get rid of that error. I figured i would post in the PHP forum to see if anyone could help me out. Here is the exact code as it is on the site:


<?php
$error = ""; // Set a variable that will be used for errors
$sendTo = ""; // Set a variable that will be used for emailing
if(isset($_POST['upload']) && $_POST['upload'] == 'Upload File') // Form is submitted
{
$whereto = $_POST['where']; // Gets post value from select menu
$whatfile = $_FILES['uploadedfile']['name']; // Gets file value from file upload input
$subject = "File uploaded to ". $whereto ." directory"; // This is the subject that will appear in the email
$from = "FTP UPLOAD <noreply@variableimageprinting.com>";
if(empty($whereto)) // Checks to see if $whereto is empty, if so echo error
{
$error = "You need to choose a directory.<br />";
}
if($whatfile == NULL) // Checks to see if file input field is empty, if so throw an error
{
$error .= "You need to choose a file.";
}
if(!empty($whereto) && $whatfile != NULL) //if no errors so far then continue uploading
{
$target_path = "$whereto/"; // The directory the file will be placed

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename($whatfile);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("Location: /about.html"); // Directs user back to page of choice
}
else
{
/* if there was a problem then throw an error */
$error .= "There was an error uploading the file, please try again!";
}
if(empty($error))
{
if($whereto == "irvineup") // Change $sentTo depending on the directory chosen
{
$sendTo = "Irvine <vip@variableimageprinting.com>"; // Change this to an email address of your own
}
if($whereto == "sandiegoup")
{
$sendTo = "San Diego <vipsd@variableimageprinting.com>"; // Change this to an email address of your own
}
/* The below will be what is shown in the email */
$body = "You have received the following from the web based upload form:\r\n";
$body .= "---------------------------------------------------------------\r\n";
$body .= "Subject: File uploaded to ". $whereto ." directory\r\n";
$body .= "File name: ". $whatfile ."\r\n";
$body .= "Upload directory: ". $whereto ."\r\n";
$body .= "Uploader's IP address: ". $_SERVER['REMOTE_ADDR'] ."\r\n";
$body .= "---------------------------------------------------------------\r\n";

/* headers used to show from field in email client */
$headers = 'From: '.$from."\r\n" .
'Reply-To: '.$from;

/* this actually sends the mail */
mail($sendTo, $subject, $body, $headers);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Variable Image Printing</TITLE>

<BODY bgColor=#FECD07 leftMargin=0 background="" topMargin=0 marginheight="0"
marginwidth="0">
<center><div>
<?php
if(!empty($error))
{
echo $error;
}
?>
</div>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<select name="where">
<option value="">Choose a directory</option>
<option value="irvineup">Irvine</option>
<option value="sandiegoup">San Diego</option>
</select>
<input type="submit" name="upload" value="Upload File" />
</form></center></BODY></HTML>



Does anyone see anythign here that could be causing this? Any help would be extremly appreciated. Thanks. :)

raf
05-03-2006, 09:06 AM
not realy sure what you are asking for.

the errormessage from your title 'Cannot modify header information - headers already sent' isn't the problem since that's just caused by your earlier errormessage on the filemove.

i don't think there is anything wrong with that code.

are you sure that that is a valid directoryname on *nix ? try modyfying your code and use a fixed path like '/test/'

if it's a valid directoryname, then it's a permission issue.
if the file is correctly moved, then it's a PHP-permission issue that you should take up with your host (bad config). you could then always solve it by suppresssing the errormessage...
if the file is not moved, then make sure PHP was write-access to the folder (--> delete the folder and recreate it with mkdir() ) and also make sure that the path is correctly posted (--> modify your code and use a fixed path)
also chack the setting for safe mode and open_basedir.

fallingintoZero
05-04-2006, 12:21 AM
thank you very much for your reposnse. the file was correctly moved, so i knew it was a php permission issue. i did contact my host which is iPowerWeb, and come to find out... they claim they don't support the move_uploaded_file command, and if a user tried to use it, then it would cause an error with that same message. so i did just use errror supression since everything worked completly fine other then that error message popping up. thank you for the help.

Nightfire
05-04-2006, 04:23 AM
Sounds like a good host if they block that function. Hope you get a discount for any other functions they block :p

raf
05-04-2006, 09:02 AM
thank you very much for your reposnse. the file was correctly moved, so i knew it was a php permission issue. i did contact my host which is iPowerWeb, and come to find out... they claim they don't support the move_uploaded_file command, and if a user tried to use it, then it would cause an error with that same message. so i did just use errror supression since everything worked completly fine other then that error message popping up. thank you for the help.
you're welcome.

this problem has been frequently reported for sites hosted on iPowerWeb (run a google) so it's realy strange they don't fix it...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum