dgriff80 Posted May 5, 2009 Share Posted May 5, 2009 So... Im creating a form that I'd like to be able to have the user upload one image under 200k that would be attached in an email. I'm confident in my skills to get the php form to work for all other data, except for attaching the file. The form itself is in a html page, as I'm not confident enough to make my entire site PHP yet, but it links to a seperate php file. I looked at the w3 schools tutorials to upload the image to the server (with a unique filename), but I'd also like to have the file sent as an attachment. I'd also like to validate that it is a .gif or .jpg or .bmp before the file is sent otherwise it's discarded. Since there is other content that will be submitted I have the submit button a "submit and upload". http://www.griffinconcepts.com/iPhone_contact.html Here's the html page... it hasn't really been cleaned up yet except for the appearance... and I have yet to build the php completely, but here's the parts of the code I have so far: HTML PAGE <form method="POST" enctype="multipart/form-data" name="iPhone_Contact" id="iPhone_Contact" action="iPhone_contact.php"> (other code is here) <input type="hidden" name="MAX_FILE_SIZE" value="200000" /> <input type="file" name="FileUpload" id="FileUpload"> (other code is here) <input type="submit" name="submit" value="Submit & Upload"> </form> AND IN THE PHP FILE... <?php // File Upload 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"]; } // Save the Uploaded File 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 "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { // move_uploaded_file($_FILES["file"]["tmp_name"], // "upload/" . $_FILES["file"]["name"]); // echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; $fileatt = $_FILES["file"]["tmp_name"] fileatt_name = 'phonepic.' . ["type"] $fileatt_type = filetype($fileatt); $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); } } } else { echo "Invalid file"; } I'm not necessarily asking for someone to write the code for me, but I sure don't know enough to make it work.... so any help would be appreciated! Link to comment https://forums.phpfreaks.com/topic/156899-noob-email-attachment-from-form/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.