Forum Moderators: coopster

Message Too Old, No Replies

Can't upload photo

         

cpl2624

6:44 pm on Nov 1, 2008 (gmt 0)

10+ Year Member



Hi Guys

Real novice here wonder if you can help?

I have a php script that worked fine passing registration details back by email, I wanted to add the ability to email a photo with the registration so found a bit of code and have been trying to intergrate it all day.

There are two problems, first I have a jpg file that is 13kb when I press submit I'm hiting an error trap (Invalid File Tim) and secondly a message about can not modify header information (see below)

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home97c/sub004/sc30742-BLLS/www/recruitmenttest.php:203) in /mounted-storage/home97c/sub004/sc30742-BLLS/www/recruitmenttest.php on line 230

I have also put the code below, be very grateful for any help and guidance

All the best

Tim

<?php
$mailto = 'tim@example.com' ;

// $subject - set to the Subject line of the email, eg
//$subject= "Feedback Form" ;

$subject = "Membership Application " ;

// the pages to be displayed, eg
$formurl= "http://www.example.com/feedback.html" ;
$errorurl= "http://www.example.com/error.html" ;
$thankyouurl= "http://www.example.com/thankyou.html" ;

$uself = 0;

$name_is_required = 1;
$age_is_required = 1;
$sex_is_required = 1;
$town_is_required = 1;
$email_is_required = 1;
$tel_no_is_required = 1;
// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) ¦¦ ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$age = $_POST['age'] ;
$sex = $_POST['sex'] ;
$town = $_POST['town'] ;
$email = $_POST['email'] ;
$tel_no = $_POST['tel_no'] ;
$bust = $_POST['bust'] ;
$cup = $_POST['cup'] ;
$hips = $_POST['hips'] ;
$waist = $_POST['waist'] ;
$dress = $_POST['dress'] ;
$height = $_POST['height'] ;
$hair = $_POST['hair'] ;
$eye = $_POST['eye'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (($email_is_required && (empty($email) ¦¦ !ereg("@", $email))) ¦¦ ($name_is_required && empty($name))) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $age ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if ( ereg( "[\r\n]", $sex ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if ( ereg( "[\r\n]", $town ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $tel_no ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $bust ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if ( ereg( "[\r\n]", $cup ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $hips ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $waist ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $dress ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $height ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $hair ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if ( ereg( "[\r\n]", $eye ) ¦¦ ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;

}
if (empty($email)) {
$email = $mailto ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
if ((($_FILES["file"]["type"] == "image/gif")
¦¦ ($_FILES["file"]["type"] == "image/jpeg")
¦¦ ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file Tim";
}
$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Age: $age\n" .
"Sex: $sex\n" .
"Town : $town\n" .
"Email of sender: $email\n" .
"Telephone No: $tel_no\n" .
"Bust: $bust\n".
"Cup: $cup\n" .
"Hips: $hips\n" .
"Waist: $waist\n" .
"Dress Size $dress\n" .
"Height: $height\n" .
"Hair Colour: $hair\n" .
"Eye Colour: $eye\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chrecuitment.php 2.10.1" );
header( "Location: $thankyouurl" );
exit ;
?>

[edited by: eelixduppy at 9:11 pm (utc) on Nov. 1, 2008]
[edit reason] exemplified [/edit]

jatar_k

12:35 pm on Nov 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld cpl2624,

the 'headers already sent' error is because you get an error message, which causes headers to be sent so the error can be output to the browser, only worry about the first error given, worry about the rest once you fix the first.

this is the if statement that is bailing

if ((($_FILES["file"]["type"] == "image/gif")
¦¦ ($_FILES["file"]["type"] == "image/jpeg")
¦¦ ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))

so you could start by echo'ing $_FILES["file"]["type"] and $_FILES["file"]["size"] and see what those variables contain.