Created
October 22, 2012 12:40
-
-
Save jonesch/3931322 to your computer and use it in GitHub Desktop.
Attaching & Validating A File. Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!empty($_FILES['resume']['name'])){ // check to see if we have a photo and a user clicks submit | |
$accept_file_formats = array( | |
'image/jpg', | |
'image/jpeg', | |
'image/png', | |
'image/gif', | |
'text/rtf', //.rtf file | |
'text/plain', //.txt file | |
'application/msword', //.doc file | |
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', //.docx file | |
'application/pdf' //.pdf file | |
); | |
if(in_array($_FILES['resume']['type'], $accept_file_formats)){ | |
$file_name = $_FILES['resume']['name']; //Get the readable file name | |
$file_base = dirname($_FILES['resume']['tmp_name']); //Get The Temp Directory defined by PHP | |
$file_tmp_name = basename($_FILES['resume']['tmp_name']); //Get PHP's version of the temporary file name | |
rename($file_base.'/'.$file_tmp_name, $file_base.'/'.$file_name); //Rename the temporary file to a readable one | |
$file_attachment_url = $file_base.'/'.$file_name; | |
$attachments = array($file_attachment_url); //store the file in an array we will send with the email later. | |
} else { | |
$attachemtn_message = 'Please provide either a .doc, .pdf, .rtf, .txt, .png, .gif, or a .jpg version of your resume. Thank You.'; | |
} | |
} | |
wp_mail($email_to, $email_subject, $email_body, $email_header, $attachments); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment