Hey All,
I'm working on an information request form. Part of the form allows users to upload an image that is attached to an email that is generated. The form works great and handles the attachement fine, however, if I try to limit the attached file types as only .jpg or .gif, I cannot get it to work.
The suspect code is as follows:
The problem I'm getting is the script always returnsPHP Code:if (is_uploaded_file($_FILES['fileatt']['tmp_name'])) {
$to = "Stokes Signs<kai@parishmedia.com>";
$from = "$name<$email>";
$subject = "Information Request From Stokes Web Site";
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
if ($_FILES['fileatt']['type'] != "image/jpg" && $_FILES['fileatt']['type'] ! = "image/gif")
{
echo "This File must be a .jpg or .gif image.";
exit;
}
else {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$msg . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
}
This is the error message I have set if the script detects that the uploade file is not a jpg or a gif. However, the files I am testing are definitely in proper format.This File must be a .jpg or .gif image.
Can anyone spot my problem?
Thanks





Bookmarks