aladiyat23 Posted July 26, 2006 Share Posted July 26, 2006 Anyone know how to tweak the email attachment script so that a form is submitted regardless if a file is uploaded?I think this is where i would make the change, just not sure how if (file_exists($tmp_name)){ if(is_uploaded_file($tmp_name)){ $file = fopen($tmp_name,'rb'); $data = fread($file,filesize($tmp_name)); fclose($file);Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15721-send-form-regardless-if-file-selected-or-not/ Share on other sites More sharing options...
trq Posted July 26, 2006 Share Posted July 26, 2006 Going to need more code than that! Quote Link to comment https://forums.phpfreaks.com/topic/15721-send-form-regardless-if-file-selected-or-not/#findComment-64208 Share on other sites More sharing options...
aladiyat23 Posted July 26, 2006 Author Share Posted July 26, 2006 ok here's a snippet of the form...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><script language="JavaScript" type="text/javascript">function zxcEnableDisable(zxcobj){zxcval=zxcobj.options[zxcobj.selectedIndex].valueif (zxcval.length<1){ return }zxcenable=zxcval.split('^')[1].split(',');for (zxc0=1;zxc0<zxcenable.length;zxc0++){zxcobj=document.getElementById(zxcenable[zxc0]);zxcobj.removeAttribute('disabled')}zxcdisable=zxcval.split('^')[0].split(',');for (zxc1=1;zxc1<zxcdisable.length;zxc1++){zxcobj=document.getElementById(zxcdisable[zxc1]);zxcobj.setAttribute('disabled','disabled')}}</script><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title></title></head><body><?phpif ($_SERVER['REQUEST_METHOD']=="POST"){ $to = "xxx"; $subject = "Data Request"; $email = $_POST['requiredemail']; $deaname = $_POST['requireddealername']; $address = $_POST['requiredaddress']; $zip = $_POST['requiredzip']; $quanity = $_POST['requiredquanity']; $list = $_POST['requiredlist']; $range = $_POST['range']; $year = $_POST['year']; $make = $_POST['make']; $other = $_POST['other']; $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; $tmp_name = $_FILES['filename']['tmp_name']; $type = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $size = $_FILES['filename']['size']; $message = " From: $email\n Dealer Name: $deaname\n Address: $address\n Zip: $zip\n Quanity: $quanity\n List: $list\n Range: $range\n Year: $year\n Make: $make\n Other: $other\n"; 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));} $headers = "From: $email\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $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"; $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" . "--{$mime_boundary}--\n";if (@mail($to, $subject, $message, $headers)) echo '<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=http://www.dmmipromotions.com/submission.html">';else echo "An error has occured. Please fill out the form and try again"; }} else {?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1"><fieldset style="width: 375px; padding:10px"><legend>Which Task would you like to accomplish?</legend><br><select onChange="zxcEnableDisable(this);" name="selection"> <option>Select One</option> <option value="D,tb1^E,tb2">Counts</option> <option value="D,tb2^E,tb1">Orders</option></select></fieldset><fieldset style="width: 375px; padding:10px" id="tb1"><legend>Upload Your spreadsheet </legend><br><span>Selected Zip Codes (.xls)</span><input name="filename" type="file" size="30"/></fieldset><input name="submit" type="submit" value="Submit"/></form><?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/15721-send-form-regardless-if-file-selected-or-not/#findComment-64228 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 You'll want to first check whether a file has been upload first, by checking whether $_FILE superglobal array is set. As if no file is uploaded I'm pretty sure no the $_FILE superglobal will not be set. Quote Link to comment https://forums.phpfreaks.com/topic/15721-send-form-regardless-if-file-selected-or-not/#findComment-64233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.