Click to See Complete Forum and Search --> : cookie problem


p80
11-21-2004, 11:23 AM
what's wrong with this script


$uploaddir = 'postimages/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
echo "Createing refrence file...\n";
$fileName = $_FILES['userfile']['name'];
setcookie('myImage', $fileName, time()+864000);
} else {
echo "File upload failed\n";
}


print_r($_FILES);

print "</pre>";


the error I get

Warning: Cannot modify header information - headers already sent by (output started at /home/partical/public_html/imgUpload.php:8) in /home/partical/public_html/imgUpload.php on line 13

line 13 is the cookie. the upload works fine, but I'm brain farting on the cookie. thanks

HaganeNoKokoro
11-21-2004, 11:31 AM
It is an error to send header information after any output. Cookies are header information, so setting one after you do an echo is an error. It can still work as long as output buffering is in place, but it's better to avoid relying on it and set cookies before any output is sent.

p80
11-21-2004, 11:37 AM
ahh, I see. thanks for the help and the quick response