Ik heb een formulier gemaakt aan de hand van wat te Googlen en dit werkt perfect, maar er is enkel de mogelijkheid om 1 bestand/foto te uploaden, maar ik wil namelijk dat met 3 foto's kan uploaden, hoe moet ik dan onderstaande code daarvoor aanpassen aub?
Reeds dank voor de hulp!
<?php
//start session
session_start();
// prints form
function print_form(){
?>
<form method="post" action="<?php echo $_SERVER[’PHP_SELF’];?>" id="uploadform" enctype="multipart/form-data">
<table width="950" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="left" valign="top" class="tablepadding">
<fieldset>
<div>
<label>Naam + Voornaam:</label>
<input name="naamvoornaam" id="naamvoornaam" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['naamvoornaam']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Adres:</label>
<input name="adres" id="adres" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['adres']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Postcode:</label>
<input name="postcode" id="postcode" size="6" type="text" class="field" value="<?= $_SESSION['myForm']['postcode']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Gemeente:</label>
<input name="gemeente" id="gemeente" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['gemeente']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Telefoon / GSM:</label>
<input name="telefoon" id="telefoon" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['telefoon']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>E-Mail:</label>
<input name="email" id="email" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['email']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Geboortedatum:</label>
<input name="geboortedatum" id="geboortedatum" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['geboortedatum']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Lengte:</label>
<input name="lengte" id="lengte" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['lengte']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Kledingmaat:</label>
<input name="kledingmaat" id="kledingmaat" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['kledingmaat']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Gewicht:</label>
<input name="gewicht" id="gewicht" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['gewicht']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label>Studies / beroep:</label>
<input name="studiesberoep" id="studiesberoep" size="40" type="text" class="field" value="<?= $_SESSION['myForm']['studiesberoep']; ?>" tabindex="1"/>
</div>
<br />
<div>
<label for="attachment1">Upload foto('s):</label>
<input name="attachment1" id="attachment1" type="file" tabindex="20">
<br />Foto's moeten kleiner zijn dan 5 MB en van het type jpg, jpeg, gif of png zijn, indien het meerdere foto's zijn, gelieve ze dan te zippen of rarren.
</div>
<br />
<div>
<label for="beschrijfjezelf">Beschrijf jezelf kort:</label>
<textarea name="beschrijfjezelf" id="beschrijfjezelf" cols="40" rows="6" class="field" tabindex="18"><?= $_SESSION['myForm']['beschrijfjezelf']; ?></textarea>
</div>
</fieldset></td>
</tr>
<tr align="left">
<td class="tablepadding" colspan="2"><p>
<input type="submit" name="submit" id="submit" value="Verzend Inschrijvingsformulier" tabindex="19"/>
</p></td>
</tr>
<tr align="center">
<td class="tablepadding" colspan="2">
<p><input type="hidden" name="submitted" value="true" /></p>
</td>
</tr>
</table>
</form>
<?php
}
// enquiry form validation
function process_form() {
// Read POST request params into global vars
$to = "[email protected]";
$naamvoornaam = trim($_POST['naamvoornaam']);
$adres = trim($_POST['adres']);
$postcode = trim($_POST['postcode']);
$gemeente = trim($_POST['gemeente']);
$telefoon = trim($_POST['telefoon']);
$email = trim($_POST['email']);
$geboortedatum = trim($_POST['geboortedatum']);
$lengte = trim($_POST['lengte']);
$kledingmaat = trim($_POST['kledingmaat']);
$gewicht = trim($_POST['gewicht']);
$studiesberoep = trim($_POST['studiesberoep']);
$beschrijfjezelf = trim($_POST['beschrijfjezelf']);
// Allowed file types. add file extensions WITHOUT the dot.
$allowtypes=array("jpg", "jpeg", "gif", "png", "zip", "rar");
// Require a file to be attached: false = Do not allow attachments true = allow file to be attached
$requirefile="true";
// Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handle it,
// post_max_size, upload_max_filesize, file_uploads, max_execution_time!
// 2048kb = 2MB, 1024kb = 1MB, 512kb = 1/2MB etc..
$max_file_size="6000";
// Thank you message
$thanksmessage="Wij bedanken u voor uw inschrijving en verwerken snel deze gegevens. Wij houden u graag op de hoogte als u opgenomen bent op onze website.\r\n\r\nCrew";
$errors = array(); //Initialize error array
if (empty($_POST['naamvoornaam']) ) {
$errors[]='Vul je naam in';
}
if (empty($_POST['email']) ) {
$errors[]='Vul je email in';
} else {
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
$errors[]='Vul een geldig emailadres in';
} // if eregi
} // if empty email
if (empty($_POST['adres']) ) {
$errors[]='Vul je adres in';
}
if (empty($_POST['postcode']) ) {
$errors[]='Vul je postcode in';
}
if (empty($_POST['gemeente']) ) {
$errors[]='Vul je gemeente in';
}
if (empty($_POST['telefoon']) ) {
$errors[]='Vul je telefoon in';
}
if (empty($_POST['geboortedatum']) ) {
$errors[]='Vul je geboortedatum in';
}
if (empty($_POST['lengte']) ) {
$errors[]='Vul je lengte in';
}
if (empty($_POST['kledingmaat']) ) {
$errors[]='Vul je kledingmaat in';
}
if (empty($_POST['gewicht']) ) {
$errors[]='Vul je gewicht in';
}
if (empty($_POST['studiesberoep']) ) {
$errors[]='Vul je studies / beroep in';
}
// checks for required file
if($requirefile=="true") {
if($_FILES['attachment1']['error']==4) {
$errors[]='Je vergat een foto toe te voegen!';
}
}
//checks attachment file
// checks that we have a file
if((!empty($_FILES["attachment1"])) && ($_FILES['attachment1']['error'] == 0)) {
// basename -- Returns filename component of path
$filename = basename($_FILES['attachment1']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
$filesize=$_FILES['attachment1']['size'];
$max_bytes=$max_file_size*1024;
//Check if the file type uploaded is a valid file type.
if (!in_array($ext, $allowtypes)) {
$errors[]="Bestandsextensie niet toegelaten: <strong>".$filename."</strong>";
// check the size of each file
} elseif($filesize > $max_bytes) {
$errors[]= "Je foto: <strong>".$filename."</strong> is te groot. Max bestandsgrootte is ".$max_file_size."kb.";
}
} // if !empty FILES
if (empty($errors)) { //If everything is OK
// send an email
$subject ="Inschrijving: $naamvoornaam.";
// Obtain file upload vars
$fileatt = $_FILES['attachment1']['tmp_name'];
$fileatt_type = $_FILES['attachment1']['type'];
$fileatt_name = $_FILES['attachment1']['name'];
// Headers
$headers = "From: $email";
// create a boundary string. It must be unique
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message ="This is a multi-part message in MIME format.\n\n";
$message.="--{$mime_boundary}\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: 7bit\n\n";
$message.="Van: ".$naamvoornaam."\n";
$message.="Adres: ".$adres."\n";
$message.="Postcode: ".$postcode."\n";
$message.="Gemeente: ".$gemeente."\n";
$message.="Telefoon: ".$telefoon."\n";
$message.="Email: ".$email."\n";
$message.="Geboortedatum: ".$geboortedatum."\n";
$message.="Lengte: ".$lengte."\n";
$message.="Kledingmaat: ".$kledingmaat."\n";
$message.="Gewicht: ".$gewicht."\n";
$message.="Studies / beroep: ".$studiesberoep."\n";
$message.="Beschrijf jezelf: ".$beschrijfjezelf."\n\n";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$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";
}
// Send the completed message
$envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
foreach ($envs as $env)
$message .= "$env: $_SERVER[$env]\n";
if(!mail($to,$subject,$message,$headers)) {
exit("Mail niet verzonden. Sorry! Er heeft zich een fout voorgedaan, rapporteer dit aub aan de administrator.\n");
} else {
echo '<div id="formfeedback"><h3>Bedankt!</h3><p>'. $thanksmessage .'</p></div>';
unset($_SESSION['myForm']);
print_form();
} // end of if !mail
} else { //report the errors
echo '<div id="formfeedback"><h3>Error!</h3><p>De volgende fouten hebben zich voorgedaan:<br />';
foreach ($errors as $msg) { //prints each error
echo " - $msg<br />\n";
} // end of foreach
echo '</p><p>Probeer aub opnieuw</p></div>';
print_form();
} //end of if(empty($errors))
} // end of process_form()
?>