Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I restrict PHP form mail attachment to certain doc types?
    primarykey
    data
    text
    <p>I would like to modify this resume uploader code I currently use to restrict the doc types of the applicant's attachment to doc, docX, rtf and PDF. I modified this from something I believe I found on SourceForge.net.</p> <p>I would also like to redirect upon successful submission. Right now the page is blank upon completion. I can probably figure that out.</p> <p>My PHP skills are not great, so I don't really know where to place the filetype validation code.</p> <pre><code>&lt;?php if ($_SERVER['REQUEST_METHOD']=="POST"){ $to="myemail@domain.com"; $subject= stripslashes($_POST['apply']); $from = stripslashes($_POST['fromname'])."&lt;".stripslashes($_POST['fromemail'])."&gt;"; $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $message= stripslashes($_POST['msg']); $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; foreach($_FILES as $userfile){ $tmp_name = $userfile['tmp_name']; $type = $userfile['type']; $name = $userfile['name']; $size = $userfile['size']; if (file_exists($tmp_name)){ if(is_uploaded_file($tmp_name)){ $file = fopen($tmp_name,'rb'); $data = fread($file,filesize($tmp_name)); fclose($file); $data = chunk_split(base64_encode($data)); } $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } } $message.="--{$mime_boundary}--\n"; if (@mail($to, $subject, $message, $headers)) echo '&lt;script type="text/javascript"&gt;alert("Resume Uploaded Successfully");&lt;/script&gt;'; else echo '&lt;script type="text/javascript"&gt;alert("Sorry Failed to Upload Your Resume");&lt;/script&gt;'; } else { ?&gt; </code></pre> <p>There's also a form validator to check for empty fields that might be of use.</p> <p>This is in the PHP document</p> <pre><code> var frmvalidator = new Validator("form1"); frmvalidator.addValidation("fromname","req","Please enter your name"); frmvalidator.addValidation("fromemail","req","Please enter your email"); frmvalidator.addValidation("apply","req","Please enter the position you are applying for"); frmvalidator.addValidation("file1","req","Please Upload Your resume"); </code></pre> <p>If anyone suggests that I add the filetype validator in the js, I can post that code. It is long and I believe it is a commonly used file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload