views:

367

answers:

4

I have an input on my form to allow a user to browse to a file location. the idea being that they can attach a resume to to the application they are getting ready to submit.

<label class="description" for="element_5">Upload a File </label>
     <div>
      <input id="element_5" name="element_5" class="element file" type="file"/>

For my text feilds and dropdowns i have been using something along the lines of

$experince = $_POST["experince"];

but I don't want the path string i want the acutall file. how do I get the file itself and how do I attach it to the email

bonus is there a easy way to limit the attachment to .doc / .pdf?

A: 

Have a look here

Frank Groeneveld
Doesn't address the (more complicated) issue of attaching the uploaded file in an email.
Rob
+1  A: 

I did something similar to this recently. It is not trivial.

Your email message will have to be a multipart Mime message. You will read in your file, encode it (using base64), then place it in your email message string in the correct spot.

This looks like a decent tutorial (that I wish I had found before): http://www.texelate.co.uk/blog/send-email-attachment-with-php/

But note that the tutorial has some escape issues:

$message . "“nn";

should be:

$message . "\n\n";

You can also look into the Mail_Mime PEAR package for help: http://pear.php.net/package/Mail%5FMime

Scott Saunders
+2  A: 

Take a look at

VolkerK
A: 

This is what i have so far but its not working

<input id="resumeup" name="resumeup"  type="file"/> 

$_FILES = $_POST["resumeup"];

      if ((($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      || ($_FILES["file"]["type"] == "image/pjpeg"))
      && ($_FILES["file"]["size"] < 20000))
      {
       if ($_FILES["file"]["error"] > 0)
       {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
       }
       else
       {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Stored in: " . $_FILES["file"]["tmp_name"];
       }
      }
Crash893