handling File uploads
Posted: Thu Sep 06, 2012 4:56 am
hi,
I working on building an online staff bio-data form meant to collect all staff basic information. Everything is working out fine except for the passport photograph will i expect to be uploaded as an attachment but is not working out. below is the html code and the corresponding server side processing code. I need your help because i want the uploaded passport photograph be sent as attachment on submition.
The input form:
And the server script:
I working on building an online staff bio-data form meant to collect all staff basic information. Everything is working out fine except for the passport photograph will i expect to be uploaded as an attachment but is not working out. below is the html code and the corresponding server side processing code. I need your help because i want the uploaded passport photograph be sent as attachment on submition.
The input form:
Code: Select all
<form name="formcheck" onsubmit="return formCheck(this);" enctype="multipart/form-data" action="send_biodata.php" method="POST">
<table width="900" border="0" cellpadding="5" cellspacing="0" style="border-top: 1px solid #CCCCCC" height="153">
<tr>
<td width="45%" height="152" valign="top">
<table width="100%" border="1" frame="void" rules="rows" bordercolor="#999999" cellpadding="0" cellspacing="0">
<tr height="35">
<td width="50%"><font color="#990000"><strong>*</strong></font> Passport Photograph:</td>
<td>
<input type="file" name="photograph" value="photograph" size="10"/>
</td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Surname</td>
<td><input type="text" name="surname" size="20"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Other Names:</td>
<td><input type="text" name="othernames" size="20"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Post Held:</td>
<td><input type="text" name="post_held" size="20"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Department:</td>
<td><input type="text" name="dept" size="20"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Home Adress:</td>
<td><input type="text" name="home_addr" size="25"/></td>
</tr>
<tr>
<td height="5"></td>
<td></td>
</tr>
</table>
</td>
<td width="%" valign="top" align="left">
<table width="100%" border="1" frame="void" rules="rows" bordercolor="#999999" cellpadding="0" cellspacing="0">
<tr height="35">
<td width="60%"><font color="#990000"><strong>*</strong></font> Branch Name:</td>
<td><input type="text" name="branch" size="15"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Religion:</td>
<td><input type="text" name="religion" size="15"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Tribe:</td>
<td><input type="text" name="tribe" size="15"/></td>
</tr><tr height="35">
<td><font color="#990000"><strong>*</strong></font> Phone No:</td>
<td><input type="text" name="phone" size="15" maxlength="11"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Nationality:</td>
<td><input type="text" name="nationality" size="15"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> LGA:</td>
<td><input type="text" name="lga" size="15"/></td>
</tr>
<tr>
<td height="5"></td>
<td></td>
</tr>
</table>
</td>
<td width="42%" valign="top">
<table width="100%" border="1" frame="void" rules="rows" bordercolor="#999999" cellpadding="0" cellspacing="0">
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> State of Origin</td>
<td><input type="text" name="state_origin" size="20"/></td>
<tr height="35">
<td width="50%">Marital Status:</td>
<td width="50%">
<select name="marrital_status">
<option selected="selected">-select-</option>
<option>Married</option>
<option>Single</option>
<option>Other</option></select>
</td>
</tr>
<tr height="35">
<td>Number of Children</td>
<td><input type="text" name="num_children" size="20"/></td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font>
<a href="javascript:showCal('Calendar1')"><font color="#333333">Employment Date:</font> <img src="calendar.jpg" border="0"/></a></td>
<td><input type="text" name="emp_date" size=20> </td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font>
<a href="javascript:showCal('Calendar2')"><font color="#333333">Date of Birth:</font> <img src="calendar.jpg" border="0"/></a></td>
<td><input type="text" name="dob" size=20> </td>
</tr>
<tr height="35">
<td><font color="#990000"><strong>*</strong></font> Contact Address</td>
<td><input type="text" name="contact_addr" size="20"/></td>
</tr>
<tr height="35">
<td></td>
<td></td>
</tr>
</table><!end of last colum table>
</td>
</tr>
</table><!end of second parent table having four columns but first three spanned>
<div align="center"><H3>Schools Attended:</H3></div>
<table width="100%" border="1" frame="void" rules="all" bordercolor="#999999" cellpadding="0" cellspacing="0">
<tr height="25">
<th width="25%">Name of Institution</th>
<th width="30%">Address of Institution</th>
<th>Duration</th>
<th width="12%">Grades</th>
<th width="10%">Qualification</th>
</tr>
<tr height="25">
<td><input type="text" name="institute_1" size="35" maxlength="50"/></td>
<td><input type="text" name="institute_1_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="institute_1_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="institute_1_dateto" size="5"/></td>
</tr>
</table>
</td>
<td>
<select name="institute_1_grade">
<option selected="selected"></option>
<option>Credit</option>
<option>Distinction</option>
<option>First Class</option>
<option>Lower Credit</option>
<option>Merit</option>
<option>Pass</option>
<option>Second Calss Lower</option>
<option>Second Calss Upper</option>
<option>SSCE</option>
<option>Third Class</option>
<option>Upper Credit</option>
</select>
</td>
<td>
<select name="institute_1_qualification">
<option selected="selected"></option>
<option>B.Sc</option>
<option>Diploma</option>
<option>M.A</option>
<option>M.Ba</option>
<option>M.Sc</option>
<option>NCE</option>
<option>HND</option>
<option>OND</option>
<option>P.hD</option>
<option>SSCE</option>
<option>Upper Credit</option>
<option>Others</option>
</select>
</td>
</tr>
<tr height="25">
<td><input type="text" name="institute_2" size="35" maxlength="50"/></td>
<td><input type="text" name="institute_2_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="institute_2_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="institute_2_dateto" size="5"/></td>
</tr>
</table>
</td>
<td>
<select name="institute_2_grade">
<option selected="selected">selelect</option>
<option>Credit</option>
<option>Distinction</option>
<option>First Class</option>
<option>Lower Credit</option>
<option>Merit</option>
<option>Pass</option>
<option>Second Calss Lower</option>
<option>Second Calss Upper</option>
<option>SSCE</option>
<option>Third Class</option>
<option>Upper Credit</option>
</select>
</td>
<td>
<select name="institute_2_qualification">
<option selected="selected">selelect</option>
<option>B.Sc</option>
<option>Diploma</option>
<option>M.A</option>
<option>M.Ba</option>
<option>M.Sc</option>
<option>NCE</option>
<option>HND</option>
<option>OND</option>
<option>P.hD</option>
<option>SSCE</option>
<option>Upper Credit</option>
<option>Others</option>
</select>
</td>
</tr>
<tr height="25">
<td><input type="text" name="institute_3" size="35" maxlength="50"/></td>
<td><input type="text" name="institute_3_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="institute_3_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="institute_3_dateto" size="5"/></td>
</tr>
</table>
</td>
<td>
<select name="institute_3_grade">
<option selected="selected">selelect</option>
<option>Credit</option>
<option>Distinction</option>
<option>First Class</option>
<option>Lower Credit</option>
<option>Merit</option>
<option>Pass</option>
<option>Second Calss Lower</option>
<option>Second Calss Upper</option>
<option>SSCE</option>
<option>Third Class</option>
<option>Upper Credit</option>
</select>
</td>
<td>
<select name="institute_3_qualification">
<option selected="selected">selelect</option>
<option>B.Sc</option>
<option>Diploma</option>
<option>M.A</option>
<option>M.Ba</option>
<option>M.Sc</option>
<option>NCE</option>
<option>HND</option>
<option>OND</option>
<option>P.hD</option>
<option>SSCE</option>
<option>Upper Credit</option>
<option>Others</option>
</select>
</td>
</tr>
<tr height="25">
<td><input type="text" name="institute_4" size="35" maxlength="50"/></td>
<td><input type="text" name="institute_4_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="institute_4_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="institute_4_dateto" size="5"/></td>
</tr>
</table>
</td>
<td>
<select name="institute_4_grade">
<option selected="selected">selelect</option>
<option>Credit</option>
<option>Distinction</option>
<option>First Class</option>
<option>Lower Credit</option>
<option>Merit</option>
<option>Pass</option>
<option>Second Calss Lower</option>
<option>Second Calss Upper</option>
<option>SSCE</option>
<option>Third Class</option>
<option>Upper Credit</option>
</select>
</td>
<td>
<select name="institute_4_qualification">
<option selected="selected">selelect</option>
<option>B.Sc</option>
<option>Diploma</option>
<option>M.A</option>
<option>M.Ba</option>
<option>M.Sc</option>
<option>NCE</option>
<option>HND</option>
<option>OND</option>
<option>P.hD</option>
<option>SSCE</option>
<option>Upper Credit</option>
<option>Others</option>
</select>
</td>
</tr>
</table>
<div align="center"><H3>Work Experience:</H3></div>
<table width="100%" border="1" frame="void" rules="all" bordercolor="#999999" cellpadding="0" cellspacing="0">
<th>Organization Name</th>
<th>Address</th>
<th>Duration</th>
<th>Position Held</th>
<tr height="25">
<td><input type="text" name="workplace_1" size="35" maxlength="50"/></td>
<td><input type="text" name="workplace_1_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="workplace_1_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="workplace_1_dateto" size="5"/></td>
</tr>
</table>
</td>
<td><input type="text" name="workpace_1_postion" size="15"/></td>
</tr>
<tr height="25">
<td><input type="text" name="workplace_2" size="35" maxlength="50"/></td>
<td><input type="text" name="workplace_2_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="workplace_2_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="workplace_2_dateto" size="5"/></td>
</tr>
</table>
</td>
<td><input type="text" name="workpace_2_postion" size="15"/></td>
</tr>
<tr height="25">
<td><input type="text" name="workplace_3" size="35" maxlength="50"/></td>
<td><input type="text" name="workplace_3_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="workplace_3_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="workplace_3_dateto" size="5"/></td>
</tr>
</table>
</td>
<td><input type="text" name="workpace_3_postion" size="15"/></td>
</tr>
<tr height="25">
<td><input type="text" name="workplace_4" size="35" maxlength="50"/></td>
<td><input type="text" name="workplace_4_addr" size="42" maxlength="80"/></td>
<td align="center">
<table width="95%">
<tr>
<td>From</td>
<td><input type="text" name="workplace_4_datefrom" size="5" /></td>
<td>To</td>
<td><input type="text" name="workplace_4_dateto" size="5"/></td>
</tr>
</table>
</td>
<td><input type="text" name="workpace_4_postion" size="15"/></td>
</tr>
</table>
<table>
<tr>
<td>Present Salary and Allowance:</td>
<td><input type="text" name="salary" size="25"/></td>
<td>Hobbies/Games:</td>
<td><input type="text" name="hobbies" size="25"/></td>
</tr>
</table>
<br />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr align="center">
<td><input type="submit" name="sub" value="Submit Form" /></td>
</tr>
</table>
</form>Code: Select all
<?php
require_once "Mail.php";
/* INSTRUCTIONS:
(1) Change username@yourdomain.com to your valid email address that is hosted on our server. Our Email server requiries SMTP Authentication and will not send emails on behalf of random people, so this is why the Sender of the email must match EXACTLY the email address that is used for SMTP authentication.
(2) Put the password for your email in the specified location below. Modify only the following 4 lines of code.
(3) For $host replace "smtp.utiware.net" with your own domain's webmail address such as "smtp.yourdomain.com"
(4) That is all. Upload it to your website and enjoy! */
$from = "mailaccount";
$to = "mailaccount";
$username = "mailaccount";
$password = "password";
$host = "smtp.domain-name"; // replace this with your domain's webmail address, for example "smtp.YourDomain.com"
$photo= $_FILES["photograph"];
$surname= $_POST["surname"];
$othernames= $_POST["othernames"];
$post_held= $_POST["post_held"];
$dept= $_POST["dept"];
$branch= $_POST["branch"];
$emp_date= $_POST["emp_date"];
$tribe= $_POST["tribe"];
$lga= $_POST["lga"];
$state_origin= $_POST["state_origin"];
$dob= $_POST["dob"];
$religion= $_POST["religion"];
$nationality= $_POST["nationality"];
$marrital_status= $_POST["marrital_status"];
$num_children= $_POST["num_children"];
$contact_addr= $_POST["contact_addr"];
$phone= $_POST["phone"];
$home_addr= $_POST["home_addr"];
$subject = $_POST["othernames"] . "\t". $_POST["surname"];;
$institute_1= $_POST["institute_1"];
$institute_1_addr= $_POST["institute_1_addr"];
$institute_1_datefrom= $_POST["institute_1_datefrom"];
$institute_1_dateto= $_POST["institute_1_dateto"];
$institute_1_grade= $_POST["institute_1_grade"];
$institute_1_qualification= $_POST["institute_1_qualification"];
$institute_2= $_POST["institute_2"];
$institute_2_addr= $_POST["institute_2_addr"];
$institute_2_datefrom= $_POST["institute_2_datefrom"];
$institute_2_dateto= $_POST["institute_2_dateto"];
$institute_2_grade= $_POST["institute_2_grade"];
$institute_2_qualification= $_POST["institute_2_qualification"];
$institute_3= $_POST["institute_3"];
$institute_3_addr= $_POST["institute_3_addr"];
$institute_3_datefrom= $_POST["institute_3_datefrom"];
$institute_3_dateto= $_POST["institute_3_dateto"];
$institute_3_grade= $_POST["institute_3_grade"];
$institute_3_qualification= $_POST["institute_3_qualification"];
$institute_4= $_POST["institute_4"];
$institute_4_addr= $_POST["institute_4_addr"];
$institute_4_datefrom= $_POST["institute_4_datefrom"];
$institute_4_dateto= $_POST["institute_4_dateto"];
$institute_4_grade= $_POST["institute_4_grade"];
$institute_4_qualification= $_POST["institute_4_qualification"];
$workplace_1= $_POST["workplace_1"];
$workplace_1_addr= $_POST["workplace_1_addr"];
$workplace_1_datefrom= $_POST["workplace_1_datefrom"];
$workplace_1_dateto= $_POST["workplace_1_dateto"];
$workpace_1_postion= $_POST["workpace_1_postion"];
$workplace_2= $_POST["workplace_2"];
$workplace_2_addr= $_POST["workplace_2_addr"];
$workplace_2_datefrom= $_POST["workplace_2_datefrom"];
$workplace_2_dateto= $_POST["workplace_2_dateto"];
$workpace_2_postion= $_POST["workpace_2_postion"];
$workplace_3= $_POST["workplace_3"];
$workplace_3_addr= $_POST["workplace_3_addr"];
$workplace_3_datefrom= $_POST["workplace_3_datefrom"];
$workplace_3_dateto= $_POST["workplace_3_dateto"];
$workpace_3_postion= $_POST["workpace_3_postion"];
$workplace_4= $_POST["workplace_4"];
$workplace_4_addr= $_POST["workplace_4_addr"];
$workplace_4_datefrom= $_POST["workplace_4_datefrom"];
$workplace_4_dateto= $_POST["workplace_4_dateto"];
$workpace_4_postion= $_POST["workpace_4_postion"];
$guarantor_1= $_POST["guarantor_1"];
$guarantor_1_addr= $_POST["guarantor_1_addr"];
$guarantor_1_phone= $_POST["guarantor_1_phone"];
$guarantor_1_relationship= $_POST["guarantor_1_relationship"];
$guarantor_2= $_POST["guarantor_2"];
$guarantor_2_addr= $_POST["guarantor_2_addr"];
$guarantor_2_phone= $_POST["guarantor_2_phone"];
$guarantor_2_relationship= $_POST["guarantor_2_relationship"];
$next_kin= $_POST["next_kin"];
$next_kin_addrr= $_POST["next_kin_addr"];
$next_kin_phone= $_POST["next_kin_phone"];
$next_kin_relationship= $_POST["next_kin_relationship"];
$salary= $_POST["salary"];
$hobbies= $_POST["hobbies"];
$message .= "\n\n ";
$message .= $firstname;
$message .= $lastname;
/*The message is assembled for sending main part of the assembling NOTE THIS*/
$subject = $_POST["surname"] . "\t". $_POST["othernames"];;
$message= "<h2>Personal Deatails</h2>";
$message .= "<strong>Surname:</strong>" ."\t". $surname . "\t". "<strong> Other Names:</strong>". "\t" . $othernames . "\t". "<strong> Photograph:</strong>". "\t" . $photo ."\n";
$message .= "<strong>Post held:</strong>" ."\t". $post_held ."\t\t\t\t\t\t\t\t". "<strong> Department:</strong>" ."\t\t\t". $dept ."\t". "<strong> Branch Name:</strong>" . "\t". $branch ."\n";
$message .= "<strong>Date of Employment:</strong>" ."\t". $emp_date ."\t". "<strong> Tribe:</strong>" ."\t". $tribe ."\t". "<strong> Local Government Area:</strong>" . "\t". $lga ."\n";
$message .= "<strong>State of Origin:</strong>" ."\t". $state_origin ."\t". "<strong> Date of Birth:</strong>" ."\t". $dob ."\t". "<strong> Religion:</strong>" . "\t". $religion ."\n";
$message .= "<strong>Nationality:</strong>" ."\t". $nationality ."\t". "<strong> Marrital Status:</strong>" ."\t". $marrital_status ."\t". "<strong> Number of Children:</strong>" . "\t". $num_children ."\n";
$message .= "<strong>Contact Address:</strong>" ."\t". $contact_addr ."\t". "<strong> Phone Number:</strong>" . "\t" . $phone."\n\n";
$message .= "<h2>Schools Attended</h2>";
$message .= "<strong>Name of Institution 1:</strong>" ."\t". $institute_1 . "\t". "<strong> Address:</strong>". "\t" . $institute_1_addr . "\t". "<strong> From:</strong>". "\t" . $institute_1_datefrom . "\t". "<strong> To:</strong>". "\t" . $institute_1_dateto . "\t". "<strong> Grades:</strong>". "\t" . $institute_1_grade ."\t". "<strong> Qualification:</strong>" ."\t". $institute_1_qualification . "\n";
$message .= "<strong>Name of Institution 2:</strong>" ."\t". $institute_2 . "\t". "<strong> Address:</strong>". "\t" . $institute_2_addr . "\t". "<strong> From:</strong>". "\t" . $institute_2_datefrom . "\t". "<strong> To:</strong>". "\t" . $institute_2_dateto . "\t". "<strong> Grades:</strong>". "\t" . $institute_2_grade ."\t". "<strong> Qualification:</strong>" ."\t". $institute_2_qualification . "\n";
$message .= "<strong>Name of Institution 3:</strong>" ."\t". $institute_3 . "\t". "<strong> Address:</strong>". "\t" . $institute_3_addr . "\t". "<strong> From:</strong>". "\t" . $institute_3_datefrom . "\t". "<strong> To:</strong>". "\t" . $institute_3_dateto . "\t". "<strong> Grades:</strong>". "\t" . $institute_3_grade ."\t". "<strong> Qualification:</strong>" ."\t". $institute_3_qualification . "\n";
$message .= "<strong>Name of Institution 4:</strong>" ."\t". $institute_4 . "\t". "<strong> Address:</strong>". "\t" . $institute_4_addr . "\t". "<strong> From:</strong>". "\t" . $institute_4_datefrom . "\t". "<strong> To:</strong>". "\t" . $institute_4_dateto . "\t". "<strong> Grades:</strong>". "\t" . $institute_4_grade ."\t". "<strong> Qualification:</strong>" ."\t". $institute_4_qualification . "\n";
$message .= "<h2>Work Experience</h2>";
$message .= "<strong>Name of Organization 1:</strong>" ."\t". $workplace_1 . "\t". "<strong> Address:</strong>". "\t" . $workplace_1_addr . "\t". "<strong> From:</strong>". "\t" . $workplace_1_datefrom . "\t". "<strong> To:</strong>". "\t" . $workplace_1_dateto ."\t". "<strong> Postion Held:</strong>" ."\t". $workpace_1_postion . "\n";
$message .= "<strong>Name of Organization 2:</strong>" ."\t". $workplace_2 . "\t". "<strong> Address:</strong>". "\t" . $workplace_2_addr . "\t". "<strong> From:</strong>". "\t" . $workplace_2_datefrom . "\t". "<strong> To:</strong>". "\t" . $workplace_2_dateto ."\t". "<strong> Postion Held:</strong>" ."\t". $workpace_2_postion . "\n";
$message .= "<strong>Name of Organization 3:</strong>" ."\t". $workplace_3 . "\t". "<strong> Address:</strong>". "\t" . $workplace_3_addr . "\t". "<strong> From:</strong>". "\t" . $workplace_3_datefrom . "\t". "<strong> To:</strong>". "\t" . $workplace_3_dateto ."\t". "<strong> Postion Held:</strong>" ."\t". $workpace_3_postion . "\n";
$message .= "<strong>Name of Organization 4:</strong>" ."\t". $workplace_4 . "\t". "<strong> Address:</strong>". "\t" . $workplace_4_addr . "\t". "<strong> From:</strong>". "\t" . $workplace_4_datefrom . "\t". "<strong> To:</strong>". "\t" . $workplace_4_dateto ."\t". "<strong> Postion Held:</strong>" ."\t". $workpace_4_postion . "\n\n";
$message .= "<strong>Present Salary</strong>" ."\t". $salary . "\t". "<strong> Hobbies/Games:</strong>". "\t" . $hobbies ."\n";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
/*This is were you redirect your customers after he/she feels out the form.*/
header("Location: thankyou.html");
}
?>