From: Vix on
I've written some code to upload a photo and update a record in my
database with the filename of the photo just uploaded. This all works
and when this action has completed a message says that it's been
successful. However I then want the photo to show up on the page.

I assume that I need to refresh the page, so added
header('Location:http://localhost:81/drake/memorials/setup-memorial.php');

but get the error:

Warning: Cannot modify header information - headers already sent by
(output started at C:\wamp\www\drake\memorials\setup-memorial.php:48) in
C:\wamp\www\drake\memorials\setup-memorial.php on line 169

At the top of the page I include the connection string file, then I have
Dreamweaver's code for restricting access to page, then Dreamweaver's
code for creating the recordset rsSetup then my code for this whole
upload and update action which is as follows:

<?php

// define a constant for the maximum upload size
define ('MAX_FILE_SIZE', 102400);

if (array_key_exists('upload', $_POST)) {
// define constant for upload folder
define('UPLOAD_DIR', 'C:/wamp/www/drake/uploads/');
// replace any spaces in original filename with underscores
// at the same time, assign to a simpler variable
$file = str_replace(' ', '_', $_FILES['image']['name']);
// convert the maximum size to KB
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
// create an array of permitted MIME types
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg');
// begin by assuming the file is unacceptable
$sizeOK = false;
$typeOK = false;

// check that file is within the permitted size
if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <=
MAX_FILE_SIZE) {
$sizeOK = true;
}

// check that file is of an permitted MIME type
foreach ($permitted as $type) {
if ($type == $_FILES['image']['type']) {
$typeOK = true;
break;
}
}

if ($sizeOK && $typeOK) {
switch($_FILES['image']['error']) {
case 0:
// move the file to the upload folder and rename it
$success = move_uploaded_file($_FILES['image']['tmp_name'],
UPLOAD_DIR.$row_rsSetup['Username'].$file);
if ($success) {
$uploadresult = "$file uploaded successfully";

//update database with new filename
$updateSQL = sprintf("UPDATE tblmemorials SET DeceasedPhoto=%s
WHERE MemorialID=%s",

GetSQLValueString($row_rsSetup['Username'].$file, "text"),
GetSQLValueString($row_rsSetup['MemorialID'],
"int"));

mysql_select_db($database_drakeconn, $drakeconn);
$Result1 = mysql_query($updateSQL, $drakeconn) or die(mysql_error());

header('Location:
http://localhost:81/drake/memorials/setup-memorial.php');
}
else {
$uploadresult = "Error uploading $file. Please try again.";
}
break;
case 3:
$uploadresult = "Error uploading $file. Please try again.";
default:
$uploadresult = "System error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['image']['error'] == 4) {
$uploadresult = 'No file selected';
}
else {
$uploadresult = "$file cannot be uploaded. Maximum size: $max.
Acceptable file types: gif, jpg";
}
}

?>

What am I doing wrong? Is there a better way to get the uploaded
picture to show up?

Thanks
Vix
From: Murray *ACE* on
This error will arise if ANYTHING is printed to the page before encountering
that header() command.

What is on this line?

> C:\wamp\www\drake\memorials\setup-memorial.php on line 169

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Vix" <user(a)example.net> wrote in message
news:g3dmi6$sp2$1(a)forums.macromedia.com...
> I've written some code to upload a photo and update a record in my
> database with the filename of the photo just uploaded. This all works and
> when this action has completed a message says that it's been successful.
> However I then want the photo to show up on the page.
>
> I assume that I need to refresh the page, so added
> header('Location:http://localhost:81/drake/memorials/setup-memorial.php');
>
> but get the error:
>
> Warning: Cannot modify header information - headers already sent by
> (output started at C:\wamp\www\drake\memorials\setup-memorial.php:48) in
> C:\wamp\www\drake\memorials\setup-memorial.php on line 169
>
> At the top of the page I include the connection string file, then I have
> Dreamweaver's code for restricting access to page, then Dreamweaver's code
> for creating the recordset rsSetup then my code for this whole upload and
> update action which is as follows:
>
> <?php
>
> // define a constant for the maximum upload size
> define ('MAX_FILE_SIZE', 102400);
>
> if (array_key_exists('upload', $_POST)) {
> // define constant for upload folder
> define('UPLOAD_DIR', 'C:/wamp/www/drake/uploads/');
> // replace any spaces in original filename with underscores
> // at the same time, assign to a simpler variable
> $file = str_replace(' ', '_', $_FILES['image']['name']);
> // convert the maximum size to KB
> $max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
> // create an array of permitted MIME types
> $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg');
> // begin by assuming the file is unacceptable
> $sizeOK = false;
> $typeOK = false;
>
> // check that file is within the permitted size
> if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <=
> MAX_FILE_SIZE) {
> $sizeOK = true;
> }
>
> // check that file is of an permitted MIME type
> foreach ($permitted as $type) {
> if ($type == $_FILES['image']['type']) {
> $typeOK = true;
> break;
> }
> }
>
> if ($sizeOK && $typeOK) {
> switch($_FILES['image']['error']) {
> case 0:
> // move the file to the upload folder and rename it
> $success = move_uploaded_file($_FILES['image']['tmp_name'],
> UPLOAD_DIR.$row_rsSetup['Username'].$file);
> if ($success) {
> $uploadresult = "$file uploaded successfully";
>
> //update database with new filename
> $updateSQL = sprintf("UPDATE tblmemorials SET DeceasedPhoto=%s WHERE
> MemorialID=%s",
>
> GetSQLValueString($row_rsSetup['Username'].$file, "text"),
> GetSQLValueString($row_rsSetup['MemorialID'],
> "int"));
>
> mysql_select_db($database_drakeconn, $drakeconn);
> $Result1 = mysql_query($updateSQL, $drakeconn) or die(mysql_error());
>
> header('Location:
> http://localhost:81/drake/memorials/setup-memorial.php');
> }
> else {
> $uploadresult = "Error uploading $file. Please try again.";
> }
> break;
> case 3:
> $uploadresult = "Error uploading $file. Please try again.";
> default:
> $uploadresult = "System error uploading $file. Contact
> webmaster.";
> }
> }
> elseif ($_FILES['image']['error'] == 4) {
> $uploadresult = 'No file selected';
> }
> else {
> $uploadresult = "$file cannot be uploaded. Maximum size: $max.
> Acceptable file types: gif, jpg";
> }
> }
>
> ?>
>
> What am I doing wrong? Is there a better way to get the uploaded picture
> to show up?
>
> Thanks
> Vix

From: Vix on
Line 169 is the line with the header command.

However I've just discovered that it was because of some whitespace
between two chunks of <?php ?>

It's now working fine!

Murray *ACE* wrote:
> This error will arise if ANYTHING is printed to the page before
> encountering that header() command.
>
> What is on this line?
>
>> C:\wamp\www\drake\memorials\setup-memorial.php on line 169
>
From: Murray *ACE* on
Yes, that will certainly do it.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Vix" <user(a)example.net> wrote in message
news:g3dne4$cl$1(a)forums.macromedia.com...
> Line 169 is the line with the header command.
>
> However I've just discovered that it was because of some whitespace
> between two chunks of <?php ?>
>
> It's now working fine!
>
> Murray *ACE* wrote:
>> This error will arise if ANYTHING is printed to the page before
>> encountering that header() command.
>>
>> What is on this line?
>>
>>> C:\wamp\www\drake\memorials\setup-memorial.php on line 169
>>

From: DizzDizzy on
there is some error in the code could u please send some updated code