Hi,
A while ago I received lots of help setting up a php form with allowed an image to be attached to the email via a web form (http://www.phpbuilder.com/board/showthread.php?t=10331248). Thanks
It works great when you want to upload an image. However, I have just noticed that the form is not sent and the viewer is redirected to the forbidden page when you do NOT add an image. I have tried removing the whole section of the script which deals with the images to test that this is actually what is causing the trouble and it worked fine, so the problem obviously lies in this bit of script:
$allowed_types = array( // List all allowed MIME Types here
'image/gif',
'image/pjpeg',
'image/jpeg',
'image/jpg',
'image/tiff',
'image/bmp',
'image/png',
);
$extArray = array('jpg', 'jpeg', 'jpe', 'gif', 'tif', 'tiff', 'png', 'bmp');
if ( is_uploaded_file($_FILES['userfile']['tmp_name']) && in_array($_FILES['userfile']['type'], $allowed_types) && in_array(substr($_FILES['userfile']['name'], strrpos($_FILES['userfile']['name'], '.')+1), $extArray )) {
$fileName = $_FILES['userfile']['tmp_name'];
$fileHandle = fopen($fileName, 'r');
$fileAttach = fread($fileHandle, filesize ($fileName));
fclose($fileHandle);
$fileAttach = chunk_split(base64_encode($fileAttach));
$emailBody .= "--FTG_BOUNDRY\n"
. "Content-Type: " . $_FILES['userfile']['type'] . "; name=\"" . $_FILES['userfile']['name'] . "\"\n"
. "Content-disposition: attachment\n"
. "Content-transfer-encoding: base64\n"
. "\n"
. "$fileAttach\n"
. "\n";
} else {
header("Location: http://www.mysite.com/forbidden.html");
exit;
}
All I can think is that possibly it's because the script says "if there's an image which complies with these restrictions, then send it , if not exit and redirect to ...forbidden". Was I so wrapped up in making sure only certain files were sent that I forgot to make it ok not to send an image at all?
If so, how would I rectify the script? (Please spell it out to me, cos my PHP knowledge is basic!).
I will look forward to a reply, since this seems to be a pretty stupid mistake that needs sorting quick!! :eek: