Este asunto me tiene loco, no consigo validar el campo de los adjuntos...
El script tiene la opcion para configurar bien subiendo el archivo y se manda directamente al email ó subiendo a la carpeta /upload, todo ello lo elijo desde la página upload.php con un true o false.
Pero el if que hay para validar sólo sirve para cuando es mandado a la carpeta /upload.
Bajar hasta abajo el código que es dónde hago el llamamiento...
Código PHP:
if ($_POST["mt-mk"]) {
$name = $_POST["name"];
$email = $_POST["email"];
$street = $_POST["street"];
$city = $_POST["city"];
$info = $_POST["info"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$securitycode = $_POST["securitycode"];
$date = date("d.m.Y | H:i");
$ip = $_SERVER['REMOTE_ADDR'];
$UserAgent = $_SERVER["HTTP_USER_AGENT"];
$host = getHostByAddr($remote);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$message = stripslashes($message);
if(!$name) {
$fehler['name'] = "<font color=#cc3333>Please enter your <strong>name</strong>.<br /></font>";
}
if (!preg_match("/^[0-9a-zA-ZÄÜÖ_.-]+@[0-9a-z.-]+\.[a-z]{2,6}$/", $email)) {
$fehler['email'] = "<font color=#cc3333>Please enter a <strong>e-mail-address</strong>.\n<br /></font>";
}
if(!$street) {
$fehler['street'] = '<font color=#cc3333>Please enter a <strong>street</strong>.<br /></font>';
if(!$city) {
$fehler['city'] = '<font color=#cc3333>Please enter your <strong>city and zipcode</strong>.<br /></font>';
if(!$info) {
$fehler['info'] = '<font color=#cc3333>Please enter who info is for <strong>(self, mother, father, etc.)</strong>.<br /></font>';
if(!$subject) {
$fehler['subject'] = '<font color=#cc3333>Please enter a <strong>subject</strong>.<br /></font>';
}
if(!$message) {
$fehler['message'] = '<font color=#cc3333>Please enter a <strong>message</strong>.<br /></font>';
}
if($sicherheits_eingabe != $_SESSION['captcha_spam']){
unset($_SESSION['captcha_spam']);
$fehler['captcha'] = "<font color=#cc3333>You entered a wrong <strong>code</strong>.<br /></font>";
}
if (!isset($fehler) || count($fehler) == 0) {
$error = false;
$errorMessage = '';
$uploadErrors = array();
$uploadedFiles = array();
$totalUploadSize = 0;
if ($cfg['UPLOAD_ACTIVE'] && in_array($_SERVER['REMOTE_ADDR'], $cfg['BLACKLIST_IP']) === true) {
$error = true;
$fehler['upload'] = '<font color=#990000>You have no authorization to upload files.<br /></font>';
}
if (!$error) {
for ($i=0; $i < $cfg['NUM_ATTACHMENT_FIELDS']; $i++) {
if ($_FILES['f']['error'][$i] == UPLOAD_ERR_NO_FILE) {
continue;
}
$extension = explode('.', $_FILES['f']['name'][$i]);
$extension = strtolower($extension[count($extension)-1]);
$totalUploadSize += $_FILES['f']['size'][$i];
if ($_FILES['f']['error'][$i] != UPLOAD_ERR_OK) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
switch ($_FILES['f']['error'][$i]) {
case UPLOAD_ERR_INI_SIZE :
$uploadErrors[$j]['error'] = 'the file is too big (PHP-Ini directive).';
break;
case UPLOAD_ERR_FORM_SIZE :
$uploadErrors[$j]['error'] = 'the file is too big (MAX_FILE_SIZE in HTML-Formular).';
break;
case UPLOAD_ERR_PARTIAL :
if ($cfg['UPLOAD_ACTIVE']) {
$uploadErrors[$j]['error'] = 'the file has been uploaded partially.';
} else {
$uploadErrors[$j]['error'] = 'the file has been sent partially.';
}
break;
case UPLOAD_ERR_NO_TMP_DIR :
$uploadErrors[$j]['error'] = 'No temporarily folder has been found.';
break;
case UPLOAD_ERR_CANT_WRITE :
$uploadErrors[$j]['error'] = 'error during saving the file.';
break;
case UPLOAD_ERR_EXTENSION :
$uploadErrors[$j]['error'] = 'unknown error due to an extension.';
break;
default :
if ($cfg['UPLOAD_ACTIVE']) {
$uploadErrors[$j]['error'] = 'unknown error on uploading.';
} else {
$uploadErrors[$j]['error'] = 'unknown error on sending the email attachments.';
}
}
$j++;
$error = true;
}
else if ($totalUploadSize > $cfg['MAX_ATTACHMENT_SIZE']*1024) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'maximum upload reached ('.$cfg['MAX_ATTACHMENT_SIZE'].' KB).';
$j++;
$error = true;
}
else if ($_FILES['f']['size'][$i] > $cfg['MAX_FILE_SIZE']*1024) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'The file is too big (max. '.$cfg['MAX_FILE_SIZE'].' KB).';
$j++;
$error = true;
}
else if (!empty($cfg['BLACKLIST_EXT']) && strpos($cfg['BLACKLIST_EXT'], $extension) !== false) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'the file extension is not permitted.';
$j++;
$error = true;
}
else if (preg_match("=^[\\:*?<>|/]+$=", $_FILES['f']['name'][$i])) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'invalid symbols in the file name (\/:*?<>|).';
$j++;
$error = true;
}
else if ($cfg['UPLOAD_ACTIVE'] && file_exists($cfg['UPLOAD_FOLDER'].'/'.$_FILES['f']['name'][$i])) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'the file already exist.';
$j++;
$error = true;
}
else {
if ($cfg['UPLOAD_ACTIVE']) {
move_uploaded_file($_FILES['f']['tmp_name'][$i], $cfg['UPLOAD_FOLDER'].'/'.$_FILES['f']['name'][$i]);
}
$uploadedFiles[] = $_FILES['f']['name'][$i];
}
}
}
if ($error) {
$errorMessage = 'following errors occured when sending the contact formular:'."\n";
if (count($uploadErrors) > 0) {
foreach ($uploadErrors as $err) {
$tmp .= '<strong>'.$err['name']."</strong><br/>\n- ".$err['error']."<br/><br/>\n";
}
$tmp = "<br/><br/>\n".$tmp;
}
$errorMessage .= $tmp.'';
$fehler['upload'] = $errorMessage;
}
}
// if no error, an email will be sent
if (!isset($fehler))
....
<tr>
<td style="width:150px"><strong>Subject: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["subject"] != "") { echo $fehler["subject"]; } ?><input name="subject" type="text" value="<?php echo $_POST[subject]; ?>" style="width:260px" maxlength="50" /></td>
</tr>
<tr>
<td style="width:150px"><strong>Message: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["message"] != "") { echo $fehler["message"]; } ?><textarea style="width:260px" name="message" cols="35" rows="10"><?php echo $_POST[message]; ?></textarea></td>
</tr>
<?php
for ($i=0; $i < $cfg['NUM_ATTACHMENT_FIELDS']; $i++) {
echo '<tr>';
echo '<td style="width:150px"><strong>Attachment:</strong></td>';
echo '<td><?php if ($_FILES['f']['error'][$i] == UPLOAD_ERR_NO_FILE) {echo "Error: No file"]; } ?><input type="file" style="width:268px" name="f[]" /></td>';
echo '</tr>';
}
?>
Código:
Gracias. <tr> <td style="width:150px"><strong>Subject: <span class="pflichtfeld">*</span></strong></td> <td><?php if ($fehler["subject"] != "") { echo $fehler["subject"]; } ?><input name="subject" type="text" value="<?php echo $_POST[subject]; ?>" style="width:260px" maxlength="50" /></td> </tr> <tr> <td style="width:150px"><strong>Message: <span class="pflichtfeld">*</span></strong></td> <td><?php if ($fehler["message"] != "") { echo $fehler["message"]; } ?><textarea style="width:260px" name="message" cols="35" rows="10"><?php echo $_POST[message]; ?></textarea></td> </tr> <tr> <td style="width:150px"><strong>Attachment: <span class="pflichtfeld">*</span></strong></td> <td><?php if ($_FILES['f']['error'][$i] == UPLOAD_ERR_NO_FILE) {echo "Error: No file"]; } ?><input type="file" style="width:268px" name="f[]" /></td> </tr>