Jump to content


Photo

send form regardless if file selected or not


  • Please log in to reply
3 replies to this topic

#1 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 26 July 2006 - 05:24 PM

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!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 July 2006 - 05:39 PM

Going to need more code than that!

#3 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 26 July 2006 - 05:52 PM

ok here's a snippet of the form...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript">
function zxcEnableDisable(zxcobj){
zxcval=zxcobj.options[zxcobj.selectedIndex].value
if (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>
<?php
if ($_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 } ?>

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 05:57 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users