Hello,
I need my web users to send an uploaded file along with their registration data.
The form will be sent via email while at the same time, the uploaded file will be stored in a folder on my server.
Take a look at the code please:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "example@noexample.com";
$email_subject = "Abstract Submission Via Journal Website";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_author_title']) ||
!isset($_POST['first_author_surname']) ||
!isset($_POST['first_author_othernames']) ||
!isset($_POST['second_author_title']) ||
!isset($_POST['second_author_surname']) ||
!isset($_POST['second_author_othernames']) ||
!isset($_POST['third_author_title']) ||
!isset($_POST['third_author_surname']) ||
!isset($_POST['third_author_othernames']) ||
!isset($_POST['presentation_type']) ||
!isset($_POST['subject_classification']) ||
!isset($_POST['presentation_title']) ||
!isset($_POST['first_author_org']) ||
!isset($_POST['first_author_phone']) ||
!isset($_POST['first_authoe_email']) ||
!isset($_POST['second_author_org']) ||
!isset($_POST['second_author_phone']) ||
!isset($_POST['second_author_email']) ||
!isset($_POST['third_author_org']) ||
!isset($_POST['third_author_phone']) ||
!isset($_POST['second_author_email']) ||
!isset($_POST['abstract_uploaded'])) {
died('We are sorry, you did not fill in required information listed above. Please do so.');
}
$first_author_title = $_POST['first_author_title']; // required
$first_author_surname = $_POST['first_author_surname']; // required
$first_author_othernames = $_POST['first_author_othernames']; // required
$second_author_title = $_POST['second_author_title']; // required
$second_author_surname = $_POST['second_author_surname']; // required
$second_author_othernames = $_POST['second_author_othernames']; // required
$third_author_title = $_POST['third_author_title']; // required
$third_author_surname = $_POST['third_author_surname']; // required
$third_author_othernames = $_POST['third_author_othernames']; // required
$presentation_type = $_POST['presentation_type']; // required
$subject_classification = $_POST['subject_classification']; // required
$presentation_title = $_POST['presentation_title']; // required
$first_author_org = $_POST['first_author_org']; // required
$first_author_phone = $_POST['first_author_phone']; // required
$first_author_email = $_POST['first_author_email']; // required
$second_author_org = $_POST['second_author_org']; // required
$second_author_phone = $_POST['second_author_phone']; // required
$second_author_email = $_POST['second_author_email']; // required
$third_author_org = $_POST['third_author_org']; // required
$third_author_phone = $_POST['third_author_phone']; // required
$third_author_email = $_POST['third_author_email']; // required
$abstract_uploaded = $_POST['abstract_uploaded']; // required
$email_message .= "first_author_title: ".clean_string($first_name)."\n";
$email_message .= "first_author_surname: ".clean_string($first_name)."\n";
$email_message .= "first_author_othernames: ".clean_string($first_name)."\n";
$email_message .= "second_author_title: ".clean_string($first_name)."\n";
$email_message .= "second_author_surname: ".clean_string($first_name)."\n";
$email_message .= "second_author_othernames: ".clean_string($first_name)."\n";
$email_message .= "third_author_title: ".clean_string($first_name)."\n";
$email_message .= "third_author_surname: ".clean_string($first_name)."\n";
$email_message .= "third_author_othernames: ".clean_string($first_name)."\n";
$email_message .= "presentation_type: ".clean_string($first_name)."\n";
$email_message .= "subject_classification: ".clean_string($subject_classification)."\n";
$email_message .= "presentation_title: ".clean_string($presentation_title)."\n";
$email_message .= "first_author_org: ".clean_string($first_author_org)."\n";
$email_message .= "first_author_phone: ".clean_string($first_author_phone)."\n";
$email_message .= "first_author_email: ".clean_string($first_author_email)."\n";
$email_message .= "second_author_org: ".clean_string($second_author_org)."\n";
$email_message .= "second_author_phone: ".clean_string($second_author_phone)."\n";
$email_message .= "second_author_email: ".clean_string($second_author_email)."\n";
$email_message .= "third_author_org: ".clean_string($third_author_org)."\n";
$email_message .= "third_author_phone: ".clean_string($third_author_phone)."\n";
$email_message .= "third_author_email: ".clean_string($third_author_email)."\n";
$email_message .= "abstract_uploaded: ".clean_string($abstract_uploaded)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?
}
?>
<!-- THE PHP SCRIPT I USED FOR PROCESSING THE FILE UPLOAD STARTS HERE -->
<?php
$target = "abstract_submitted/";
$target = $target . basename( $_FILES['abstract_uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['abstract_ uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['abstract_uploaded']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
A prompt assistance will be much appreciated. Thanks.