DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Michael has posted 27 posts at DZone. View Full User Profile

Single File Upload

04.09.2007
| 283 views |
  • submit to reddit
        // Upload a single file

<?
if (isset($_POST['submit']))
{

	 $email = $_POST['email'];
	 $fname = $_POST['fname'];
	 $lname = $_POST['lname'];
	 $address1 = $_POST['address1'];
	 $address2 = $_POST['address2'];
	 $city = $_POST['city'];
	 $state = $_POST['state'];
	 $zip = $_POST['zip'];
	 $country = $_POST['country'];
	 $phone1 = $_POST['phone1'];
	 $phone2 = $_POST['phone2']; 
	 $engrave_text = $_POST['engrave_text'];
	 $font = $_POST['font'];
	 $text_placement = $_POST['text_placement'];
	// $image_name = $_POST['image_name'];
	 $image_size = $_POST['image_size'];
	 $image_placement = $_POST['image_placement'];
	 $special_instructions = $_POST['special_instructions'];
		 
		$id = md5(uniqid(rand()));
		$id_hidden=$id;
		$TODAY = date("Ymd");



//if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") && ($_FILES["file"]["size"] < 2097152)) //2MB upload limit
//if (($_FILES['file']['type'] == 'image/gif') || ($_FILES['file']['type'] == 'image/jpeg'))

if ($_FILES['file']['type'] != "image/gif" && 
	$_FILES['file']['type'] != "image/jpeg" && 
	$_FILES['file']['type'] != "image/pjpeg" ||
	$_FILES['file']['size'] > 2097152) 
{ 
	?>
	<script language="JavaScript">
  var count= 0

  function wait() {
	count ++
	if(count == 1 ){
	  window.document.location.href='order.php?cmd=file_error'
	}
	else{
	  setTimeout("wait()",1000)
	}
  }
wait();

</script>
	<? 
}
else
  {
  
   $orig_filename = $_FILES["file"]["name"];
   $file_name = explode(".", $_FILES["file"]["name"]);
   $filenameext = $file_name[count($file_name)-1];
   unset($file_name[count($file_name)-1]);
         $file_name = implode(".", $file_name);
   
   $file_name = $id_hidden.".".$filenameext;
   // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   
   //Upload file
	 move_uploaded_file($_FILES["file"]["tmp_name"], "image_upload/" . $file_name);
    
    
    		
		//Write data to db
		$sql = "INSERT INTO entry_form (id,fname,lname,email,address1,address2,city,state,country,zip,phone1,phone2,engrave_text,font,text_placement,image_name,image_size,image_placement,special_instructions,entry_date) ";
		$sql .= "VALUES ('$id_hidden','$fname','$lname','$email','$address1','$address2','$city','$state','$country','$zip','$phone1','$phone2','$engrave_text','$font','$text_placement','$file_name','$image_size','$image_placement','$special_instructions','$TODAY')";
		$result = mysql_query($sql); //or $error = 1;
		
		mysql_close();


	// Email Order Conf. to User
	
	$subject = "New Order Entry";
	$message = "Dear $fname $lname,
 
Thank you for your order

";

	mail($email, $subject, $message, "From: AmplifiedLightLaser<someone@amplifiedlightlaser.com>\nX-Mailer: PHP/" . phpversion());




	// Email New Entry to contest@discovercottonbay.com
	//$admin_email = "sales@amplifiedlightlaser.com";
	$admin_email = "andrew@baxterwebdesign.com";
	$admin_subject = "*** New Order Entry ***";
	$admin_message = "


First Name: $fname
Last Name: $lname

Address: $address1
Address2: $address2
City: $city
State: $state
Zip: $zip
Phone: $phone1
Second Phone: $phone2

Engrave Text: $engrave_text

Font: $font

Text Placement: $text_placement
Image Placement: $image_placement

Special Instructions: $special_instructions

View online at-
http://www.amplifiedlightlaser.com/temp1/admin_order.php?cmd=detail&id=$id_hidden


";


	mail($admin_email, $admin_subject, $admin_message, "From: AmplifiedLightLaser.com<sales@amplifiedlightlaser.com>\nX-Mailer: PHP/" . phpversion());	
?>



<script language="JavaScript">
  var count= 0

  function wait() {
	count ++
	if(count == 1 ){
	  window.document.location.href='order.php?cmd=thank_you'
	}
	else{
	  setTimeout("wait()",1000)
	}
  }
wait();

</script>


    
  <?  
    
    
   
  }
?>
		

<?
}
?>

<? if (isset($cmd) && $cmd == "thank_you"): ?>
<strong>Your information has been submitted successfully.</strong>
<?php endif; ?>

<? if (isset($cmd) && $cmd == "file_error"): ?>
<strong>Your information was not saved.<br />Your image could not be uploaded.  It is either not in gif or jpg format or it exceeds the 2MB file size limit!</strong>
<?php endif; ?>


<form name="order" action="<?=$_SERVER['order.php']?>" method="post" enctype='multipart/form-data' onSubmit='return validate();'>
<!--
        <div align="left"> <font face="Arial, Helvetica, sans-serif">
          <input type=hidden name="recipient" value="SALES@amplifiedlightlaser.com">
          <input type=hidden name="subject" value="Contact Form Results">
          <input type=hidden name="required" value="FirstName,LastName,email,">
-->
<table border="1" width="80%" align="left">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>
First Name: 
</td>
<td><input type="text" name="fname" id="fname" size=20></td>
</tr>
<tr>
<td>
Last Name:
</td>
<td><input type="text" name="lname" id="lname" size=20></td>
</tr>
<tr>
<td>
Email:
</td>
<td><input type="text" name="email" id="email" size=20></td>
</tr>
<tr>
<td>
Address 1:
</td>
<td><input type="text" name="address1" id="address1" size=20></td>
</tr>
<tr>
<td>
Address 2:
</td>
<td><input type="text" name="address2" id="address2" size=20></td>
</tr>
<tr>
<td>
City:
</td>
<td><input type="text" name="city" id="city" size=20></td>
</tr>
<tr>
<td>
State:
</td>
<td><input type="text" name="state" id="state" size=20></td>
</tr>
<tr>
<td>
Zip:
</td>
<td><input type="text" name="zip" id="zip" size=6></td>
</tr>
<tr>
<td>
Phone 1:
</td>
<td><input type="text" name="phone1" id="phone1" size=10></td>
</tr>
<TR>
<TD>
Phone 2:
</TD>
<td><input type="text" name="phone2" id="phone2" size=10></td>
</TR>
<tr>
<td>
</table>
<table>
<h3>Order Details</h3>
</td>
</tr>
<tr>
<td>
Text to be engraved on the product
</td>
</tr>
<tr>
<td>
<textarea cols=40 rows=10 name="engrave_text"></textarea>
</td>
</tr>
<TR>
<TD>
What Font would you like the text in?
</TD>
</TR>
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td >
<input type="radio" name="font" value="Arial">
</td>
<td>Arial</td> 
<td><img src="images/arial.gif" alt="" width="400" height="30" border="0"></td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Cataneo"></td>
<td>Cataneo </td>
<td><img src="images/cataneo.gif" alt="" width="400" height="30" border="0"></td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="copper_plate"></td>
<td>Copper Plate</td>
<td><img src="images/copper.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Courier_new"></td>
<td>Courier New</td>
<td><img src="images/courier.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Engravers"></td>
<td>Engravers</td>
<td><img src="images/engravers.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Palatio"></td>
<td>Palatio</td>
<td><img src="images/palatio.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<!--
<tr>
<td>
<input type="radio" name="font" value="Palatio"></td>
<td>Palatio</td>
<td><img src="images/palatio.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
-->
<tr>
<td>
<input type="radio" name="font" value="Wedding"></td>
<td>Wedding</td>
<td><img src="images/Weddingtxt.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Edwarding"></td>
<td>Edwarding Script</td>
<td><img src="images/esarding.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
<tr>
<td>
<input type="radio" name="font" value="Humanist"></td>
<td>Humanist</td>
<td><img src="images/Humanst970.gif" alt="" width="400" height="30" border="0">
</td>
</tr>
</table>
<table>
<TR>
<TD>
Where do you want the text placed on the product (i.e. top center, bottom...)?
</TD>
</TR>
<tr>
<td>
<input type="text" name="text_placement" size=20>
</td>
</tr>
<TR>
<TD>
Do you have an image that you want placed on the product? <br />
<!-- <input name="Browse" type=submit value="Browse">-->
(Images must be in gif or jpeg format, and less than 2MB)<br />
<input type="file" name="file" id="file" /> 
</TD>
</TR>
<TR>
<TD>
Where do you want the image placed on the product (i.e. top center, bottom...)?
</TD>
</TR>
<tr>
<td>
<input type="text" name="image_placement" size=20>
</td>
</tr>
<TR>
<TD>
OTHER SPECIAL INSTURCTIONS
</TD>
</TR>
<tr>
<td>
<textarea cols=40 rows=10 name="special_instructions"></textarea>
</td>
</tr>
<tr>
<td>
Depending on the size of your image, processing this form may take a few minutes.<br />
<input name="submit" type=submit value="Send">
<input value="Clear All" type="reset" name="reset">
</td>
</tr>
</table>
</table>
</form>