954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help in sending uploaded file along with other data in a web form

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.";
		echo $error."";
		echo "Please go back and fix these errors.";
		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."; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files"; 
 $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.

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

It would be helpful if you stated which error you have, or what part is not working. Just pasting a piece of code won't get you much assistence.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Thanks for the after thought. On pushing the button, the php script file echo "Sorry, there was a problem uploading your file." as indicated on line 140 of the script. Also, no data was delivered to the email account indicated. I hope this sheds some light on the issue.

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

You did change the $email_to I hope. Also, there is a space on line 134 that should not be there.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

I have noticed the space that was not suppose to be there and corrected it however, I seem not to comprehend the $email_to you hinted at. Please a bit more explanation may prove useful.

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

Line 94 uses $email_to. This variable is set on line 5 to a non existant address. Change that line.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Pritaeas, thanks for your observations. I could get the uploaded files sent to the destination directory successfully however, the form data could not be sent to the genuine email address (not the one I specified in the code I posted). I cold get the uploaded file but the form data was not delivered.
Please advise.

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

$email_from is never given a value...

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

I am yet to resolve this issue. Will someone look into why this script would upload file to my server successfully but not send the form data via email.

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "me@myemailaddress.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.";
		echo $error."";
		echo "Please go back and fix these errors.";
		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 -->

			</br>
			</br>
			</br>
			</br>
			</br>
			</br>
			</br><span class="style19">Your registration was successful. Thank you.
			
			</span>

<?
}
?>
<!-- End of the registration to email script -->

<!-- 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."; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files"; 
 $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."; 
 } 
 } 
 ?>


What could be wrong? I need you guys' advice.

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

See previous comment, still unresolved.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Am I right?

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "emiola@qestinfosystems.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.";
		echo $error."";
		echo "Please go back and fix these errors.";
		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_from = $_POST['first_author_email']; // required


	
	$email_message .= "first_author_title: ".clean_string($first_name)."\n";
	$email_message .= "first_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "Email: ".clean_string($email_from)."\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 -->

			</br>
			</br>
			</br>
			</br>
			</br>
			</br>
			</br><span class="style19">Your registration was successful. Thank you.
			
			</span>

<?
}
?>
<!-- End of the registration to email script -->

<!-- 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."; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files"; 
 $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."; 
 } 
 } 
 ?>


For Pritaeas

emiola
Junior Poster in Training
51 posts since Jul 2008
Reputation Points: 10
Solved Threads: 1
 

At least now it is set.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Remove the error suppression (@) from the mail function on line 98. After this, run a test and see if you get any errors.

If the above didn't help, try putting this at the top of your code:

error_reporting(-1);
ini_set('display_errors','On');


and let us know what comes up.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: