PHP upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

PHP upload

Post by mikewooten »

i have an PHP upload script that works, but i have a form with 3 different sections to it and the upload script needs to work separately with each of the different sections, The sections are Business Cards, Postcards, and Other. The upload script needs to work differently within this form.
Right now how i have it set up is that the upload script works the same with all 3 sections, but it needs to work separetly, so can you help me out with this in trying to get this upload script to work seperately within this form?
thanks
the page i am working on that you can take a look at is:
http://www.mcnealeyprinting.com/test/order.php
This is the code that i am working with, it is an html page with php as the upload script.




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>McNealy and Associates</title>
<link rel="stylesheet" href="mcNealy.css" />
<script src="utility.txt"></script>

Code: Select all


<script type="text/javascript">
<!--

// function switchDiv()
//  this function takes the id of a div
//  and calls the other functions required
//  to show that div
//
function switchDiv(div_id)
{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    hideAll();
    changeObjectVisibility(div_id,"visible");
  }
  else 
  {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
}

// function hideAll()
//  hides a bunch of divs
//
function hideAll()
{
   changeObjectVisibility("ez","hidden");
   changeObjectVisibility("full","hidden");
   changeObjectVisibility("superduper","hidden");
}

// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}
// -->
</script>

Code: Select all





</head>

<body>

<div id="centerPage"> 
  <div id="whopper">
    <div id="header"></div>
    <div id="nav" class="nav" align="right"> <img src="images/shim.gif" border="0" height="5" width="1" /><br />
      <a href="index.html">HOME</a> | <a href="about.html">ABOUT</a> | <a href="order.php">ORDER</a> 
      | <a href="services.html">SERVICES</a> | <a href="contact.php">CONTACT</a> 
      &nbsp;&nbsp; </div>
    <div id="shadow"></div>
    <div id="content"> 
      <div id="pictures"> <img src="images/rollers.jpg" border="0" /><br />
        <img src="images/dieCut.jpg" border="0" /><br />
        <img src="images/blackPrinter.jpg" border="0" /> 
      <div id="text" class="bodyText"> <span class="mainHead"><br>Order </span> <br />
        <br />
        <span class="smallText"> We offer a simple and convenient way to submit 
        your orders to us directly online. This process ensures that we obtain 
        the most complete information about you and your order. To order online, 
        please follow these steps:<br />
        1. Collect all of your important files and documents (pictures, fonts, 
        PDFs, etc.) into one folder.<br />
        2. Compress the folder using ZIP compression for Windows or SIT (Stuffit) 
        compression for Macintosh.<br />
        3. Make sure that total size of the compressed file is 80 MB or less. 
        If it is larger than 80 MB, please send us a CD, DVD or ZIP disk, or arrange 
        for another method to deliver the files to us. <br />
        <br />
        When you have completed the steps above you are ready to order online...please 
        complete the form below </span> 
        <form name="the_form">
		<font style="color:#3399FF">Choose One:</font> 
          <input type="radio" name="form_type" value="ez"
  onClick="switchDiv('ez');">
          Business Cards 
          <input type="radio" name="form_type" value="full"
  onClick="switchDiv('full');">
          Postcards 
          <input type="radio" name="form_type" value="full"
  onClick="switchDiv('superduper');">
          Other 
        </form>
        <div id="ez" style="position:absolute;visibility:hidden;top:200px;left:5px;"> 
          <form name="ez_form" method="POST" 
  action="http://64.175.14.218/cgi-bin/thanks.cgi"><br /><br>



            <table>
              <tr> 
                <td>Final Size:</td>
                <td> <select name="final_size">
                    <option value="final_size">3.5" x 2"</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Print Type:</td>
                <td> <select name="print_type">
                    <option value="print_type">--Select Print Type--</option>
                    <option value="1/0">1/0</option>
                    <option value="1/1">1/1</option>
                    <option value="2/0">2/0</option>
                    <option value="2/2">2/2</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Material:</td>
                <td> <select name="material">
                    <option value="material">80PT Cover </option>
                    <option value="material">100 PT Cover</option>
                    <option value="material">10PT</option>
                    <option value="material">12 Pt. Covers C1S</option>
                    <option value="material">Field for Gloss and Non Gloss </option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Gloss:</td>
                <td> <select name="gloss">
                    <option value="gloss">Gloss</option>
                    <option value="gloss">Non-Gloss</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Type of Service:</td>
                <td> <select name="material">
                    <option value="material">24 Hours</option>
                    <option value="material">48 Hours</option>
                    <option value="material">5 days</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Format:</td>
                <td> <select name="format">
                    <option value="format">--Select Format--</option>
                    <option value="PDF">PDF</option>
                    <option value="photoshop">Photoshop</option>
                    <option value="illustrator">Illustrator</option>
                    <option value=".TIFF">.TIFF</option>
                    <option value=".EPS">.EPS</option>
                    <option value="quark">QuarkXpress</option>
                    <option value="indesign">Indesign</option>
                    <option value="corel_draw">Corel Draw</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Quantity:</td>
                <td> <select name="quantity">
                    <option value="quantity">--Select Quantity--</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="1500">1500</option>
                    <option value="2000">2000</option>
                    <option value="2500">2500</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                  </select> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Sub-Total:</strong> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Total:</strong> </td>
              </tr>
            </table>
          <input type="submit" value="continue">
          </form>



Code: Select all


		  
          <?php 

// specify the directory where the uploaded file should end up 
$path = 'upload/' ; 

// specify the filetypes allowed 
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png'); 

// specify the max filesize in bytes 
$max_size = 200000; 

if(isset($HTTP_POST_FILES['userfile'])) 
{ 
  if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) 
  { 
   if($HTTP_POST_FILES['userfile']['size'] < $max_size) 
   { 
    if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed)) 
    { 
     if(!file_exists($path . $HTTP_POST_FILES['userfile']['name'])) 
     { 
      if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name'])) 
      { 
       $html_output = 'Upload sucessful!<br>'; 
       $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
       $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>'; 
       $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br><br>'; 
	   $html_output .= '<a href="order.php">Back to upload form</a>';
	   $image = $HTTP_POST_FILES['userfile']['name'] ; 
      }else{ 
       $html_output = 'Upload failed!<br>'; 
       if(!is_writeable($path)) 
       { 
        $html_output = 'The Directory "'.$path.'" must be writeable!<br>'; 
		$html_output .= '<a href="order.php">Back to upload form</a>';
       }else{ 
        $html_output = 'an unknown error ocurred.<br>';  
		$html_output .= '<a href="order.php">Back to upload form</a>';     
       } 
      } 
     }else{ 
      $html_output = 'The file already exists<br>';
	  $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
	  $html_output .= '<a href="order.php">Back to upload form</a>'; 
     } 
    }else{ 
     $html_output = 'Wrong file type<br>'; 
	 $html_output .= '<a href="order.php">Back to upload form</a>';
    } 
   }else{ 
    $html_output = 'The file is too big<br>'; 
	$html_output .= '<a href="order.php">Back to upload form</a>';
   } 
  } 
}else{ 
  $html_output = '<TABLE BGCOLOR="#dcdcdc" BORDER="1" bordercolor="#000066" CELLSPACING="2" CELLPADDING="2" WIDTH="30%">';
  $html_output .= '<tr><td align="center">';
  $html_output .= '<strong><div align="center">Upload File!</div></strong>';
  $html_output .= '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">'; 
  $html_output .= '<input type="file" name="userfile"><br>'; 
  $html_output .= '<input type="submit" value="upload">'; 
  $html_output .= '</form>'; 
  $html_output .= '</td></tr></table>';

} 

echo $html_output; 	  

?>	

Code: Select all

		  
        </div>
        <div id="full" style="position:absolute;visibility:hidden;top:200px;left:5px;"> 
          <form name="full_form" method="POST" 
  action="http://64.175.14.218/cgi-bin/thanks.cgi"><br /><br>
            <table>
              <tr> 
                <td>Final Size:</td>
                <td> <select name="final_size_post">
                    <option value="4x6">4" x 6"</option>
                    <option value="4x9">4" x 9"</option>
                    <option value="5x7">5" x 7"</option>
                    <option value="5.5x8.5">5.5" x 8.5"</option>
                    <option value="6x9">6" x 9"</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Print Type:</td>
                <td> <select name="print_type">
                    <option value="print_type">--Select Print Type--</option>
                    <option value="4/0">4/0</option>
                    <option value="4/1">4/1 (black)</option>
                    <option value="4/4">4/4</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Material:</td>
                <td> <select name="material">
                    <option value="material">10 Pt. Covers C1S</option>
                    <option value="material">10 Pt. Covers C2S</option>
                    <option value="material">12 Pt. Covers C2S</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Type of Service:</td>
                <td> <select name="material">
                    <option value="material">24 Hours</option>
                    <option value="material">48 Hours</option>
                    <option value="material">5 days</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Format:</td>
                <td> <select name="format">
                    <option value="format">--Select Format--</option>
                    <option value="PDF">PDF</option>
                    <option value="photoshop">Photoshop</option>
                    <option value="illustrator">Illustrator</option>
                    <option value=".TIFF">.TIFF</option>
                    <option value=".EPS">.EPS</option>
                    <option value="quark">QuarkXpress</option>
                    <option value="indesign">Indesign</option>
                    <option value="corel_draw">Corel Draw</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Quantity:</td>
                <td> <select name="quantity">
                    <option value="quantity">--Select Quantity--</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="1500">1500</option>
                    <option value="2000">2000</option>
                    <option value="2500">2500</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                  </select> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Sub-Total:</strong> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Total:</strong> </td>
              </tr>
            </table>
            <input type="submit" value="continue">
          </form>
		  


Code: Select all



		            <?php 

// specify the directory where the uploaded file should end up 
$path2 = 'upload/' ; 

// specify the filetypes allowed 
$allowed2 = array('image/gif','image/pjpeg','image/jpeg','image/png'); 

// specify the max filesize in bytes 
$max_size2 = 200000; 

if(isset($HTTP_POST_FILES['userfile'])) 
{ 
  if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) 
  { 
   if($HTTP_POST_FILES['userfile']['size'] < $max_size2) 
   { 
    if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed2)) 
    { 
     if(!file_exists($path2 . $HTTP_POST_FILES['userfile']['name'])) 
     { 
      if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path2.$HTTP_POST_FILES['userfile']['name'])) 
      { 
       $html_output2 = 'Upload sucessful!<br>'; 
       $html_output2 .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
       $html_output2 .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>'; 
       $html_output2 .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br><br>'; 
	   $html_output2 .= '<a href="order.php">Back to upload form</a>';
	   $image2 = $HTTP_POST_FILES['userfile']['name'] ; 
      }else{ 
       $html_output2 = 'Upload failed!<br>'; 
       if(!is_writeable($path2)) 
       { 
        $html_output2 = 'The Directory "'.$path2.'" must be writeable!<br>'; 
		$html_output2 .= '<a href="order.php">Back to upload form</a>';
       }else{ 
        $html_output2 = 'an unknown error ocurred.<br>';  
		$html_output2 .= '<a href="order.php">Back to upload form</a>';     
       } 
      } 
     }else{ 
      $html_output2 = 'The file already exists<br>';
	  $html_output2 .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
	  $html_output2 .= '<a href="order.php">Back to upload form</a>'; 
     } 
    }else{ 
     $html_output2 = 'Wrong file type<br>'; 
	 $html_output2 .= '<a href="order.php">Back to upload form</a>';
    } 
   }else{ 
    $html_output2 = 'The file is too big<br>'; 
	$html_output2 .= '<a href="order.php">Back to upload form</a>';
   } 
  } 
}else{ 
  $html_output2 = '<TABLE BGCOLOR="#dcdcdc" BORDER="1" bordercolor="#000066" CELLSPACING="2" CELLPADDING="2" WIDTH="30%">';
  $html_output2 .= '<tr><td align="center">';
  $html_output2 .= '<strong><div align="center">Upload File!</div></strong>';
  $html_output2 .= '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">'; 
  $html_output2 .= '<input type="file" name="userfile"><br>'; 
  $html_output2 .= '<input type="submit" value="upload">'; 
  $html_output2 .= '</form>'; 
  $html_output2 .= '</td></tr></table>';

} 

echo $html_output2; 	  

?>
	

Code: Select all

		  
        </div>
        <div id="superduper" style="position:absolute;visibility:hidden;top:200px;left:5px;"> 
          <form name="full_form" method="POST" 
  action="http://64.175.14.218/cgi-bin/thanks.cgi"><br /><br>
            <table>
              <tr> 
                <td>Final Size:</td>
                <td> <select name="final_size_post">
                    <option value="5.5x8.5">5.5" x 8.5"</option>
                    <option value="6x9">6" x 9"</option>
                    <option value="7x10">7" x 10"</option>
                    <option value="8.5x11">8.5" x 11"</option>
                    <option value="9x12">9" x 12"</option>
                    <option value="9x16">9" x 16"</option>
                    <option value="11x17">11" x 17"</option>
                    <option value="17x12">17" x 12"</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Print Type:</td>
                <td> <select name="print_type">
                    <option value="print_type">--Select Print Type--</option>
                    <option value="1/0">1/0</option>
                    <option value="1/1">1/1</option>
                    <option value="2/0">2/0</option>
                    <option value="2/2">2/2</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Material:</td>
                <td> <select name="material">
                    <option value="material">70 lbs. text</option>
                    <option value="material">100 lbs. Cover</option>
                    <option value="material">10 PT</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Gloss:</td>
                <td> <select name="gloss">
                    <option value="gloss">Gloss</option>
                    <option value="gloss">Non-Gloss</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Type of Service:</td>
                <td> <select name="material">
                    <option value="material">24 Hours</option>
                    <option value="material">48 Hours</option>
                    <option value="material">5 days</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Format:</td>
                <td> <select name="format">
                    <option value="format">--Select Format--</option>
                    <option value="PDF">PDF</option>
                    <option value="photoshop">Photoshop</option>
                    <option value="illustrator">Illustrator</option>
                    <option value=".TIFF">.TIFF</option>
                    <option value=".EPS">.EPS</option>
                    <option value="quark">QuarkXpress</option>
                    <option value="indesign">Indesign</option>
                    <option value="corel_draw">Corel Draw</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Quantity:</td>
                <td> <select name="quantity">
                    <option value="quantity">--Select Quantity--</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="1500">1500</option>
                    <option value="2000">2000</option>
                    <option value="2500">2500</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                  </select> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Sub-Total:</strong> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Total:</strong> </td>
              </tr>
            </table>
            <input type="submit" value="continue">
          </form>

Code: Select all

		  
		  		            <?php 

// specify the directory where the uploaded file should end up 
$path3 = 'upload/' ; 

// specify the filetypes allowed 
$allowed3 = array('image/gif','image/pjpeg','image/jpeg','image/png'); 

// specify the max filesize in bytes 
$max_size3 = 200000; 

if(isset($HTTP_POST_FILES['userfile'])) 
{ 
  if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) 
  { 
   if($HTTP_POST_FILES['userfile']['size'] < $max_size3) 
   { 
    if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed3)) 
    { 
     if(!file_exists($path3 . $HTTP_POST_FILES['userfile']['name'])) 
     { 
      if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path2.$HTTP_POST_FILES['userfile']['name'])) 
      { 
       $html_output3 = 'Upload sucessful!<br>'; 
       $html_output3 .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
       $html_output3 .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>'; 
       $html_output3 .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br><br>'; 
	   $html_output3 .= '<a href="order.php">Back to upload form</a>';
	   $image3 = $HTTP_POST_FILES['userfile']['name'] ; 
      }else{ 
       $html_output3 = 'Upload failed!<br>'; 
       if(!is_writeable($path3)) 
       { 
        $html_output3 = 'The Directory "'.$path3.'" must be writeable!<br>'; 
		$html_output3 .= '<a href="order.php">Back to upload form</a>';
       }else{ 
        $html_output3 = 'an unknown error ocurred.<br>';  
		$html_output3 .= '<a href="order.php">Back to upload form</a>';     
       } 
      } 
     }else{ 
      $html_output3 = 'The file already exists<br>';
	  $html_output3 .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; 
	  $html_output3 .= '<a href="order.php">Back to upload form</a>'; 
     } 
    }else{ 
     $html_output3 = 'Wrong file type<br>'; 
	 $html_output3 .= '<a href="order.php">Back to upload form</a>';
    } 
   }else{ 
    $html_output3 = 'The file is too big<br>'; 
	$html_output3 .= '<a href="order.php">Back to upload form</a>';
   } 
  } 
}else{ 
  $html_output3 = '<TABLE BGCOLOR="#dcdcdc" BORDER="1" bordercolor="#000066" CELLSPACING="2" CELLPADDING="2" WIDTH="30%">';
  $html_output3 .= '<tr><td align="center">';
  $html_output3 .= '<strong><div align="center">Upload File!</div></strong>';
  $html_output3 .= '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">'; 
  $html_output3 .= '<input type="file" name="userfile"><br>'; 
  $html_output3 .= '<input type="submit" value="upload">'; 
  $html_output3 .= '</form>'; 
  $html_output3 .= '</td></tr></table>';

} 

echo $html_output3; 	  

?>
	

Code: Select all

		  
        </div>
      </div>
      <br>
      <br><br><br>   <br><br><br>   <br><br><br>   <br><br><br>  
      <table cellpadding="10" cellspacing="10" width="750">
        <tr> 
          <td valign="top"><img src="images/3x2.jpg" /></td>
          <td valign="top"> <span class="bodyText"> How to Create Bleeds<br>
            To create bleeds, make your document larger than the final CUT SIZE. 
            We require that you make your document 0.125" larger on all four sides, 
            therefore, the size with bleeds will be 0.25" larger than the final 
            cut size in both dimensions. For example, if you are printing a postcard 
            with a final cut size of 4" x 6", then the size with bleeds (BLEED 
            SIZE) will be 4.25" x 6.25". <br>
            <br>
            The best way to design keeping bleeds in mind is to make use of visual 
            guides found in most graphics programs. Start by making your document 
            size equal to the BLEED SIZE (for a 4" x 6" postcard, make it 4.25" 
            x 6.25"). Now place guides 0.125" in from these edges, all the way 
            around. These guides are where the document/card will be cut (CUT 
            EDGE). Anything you want to bleed off the edge of the card must extend 
            past your guides out to the BLEED EDGE. If photos and backgrounds 
            do not extend past these guides, (if they do not bleed), white may 
            show around the edges when we cut the cards, due to slight movement 
            during the cutting process. <a href="http://www.impressionsinprint.ca/bleedpicture.html">http://www.impressionsinprint.ca/bleedpicture.html</a> 
            <br>
            <br>
            </span> </td>
        </tr>
      </table>
      <!--end text-->
    </div>
    <!--end content--><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
	 <br><br><br>   <br><br><br>   <br>
    <div id="footer" class="footerText" align="center"> <img src="images/shim.gif" border="0" height="3" width="1" /><br />
      McNealey & Associates, Inc. Copyright 2006 | Developed by <a href="http://www.vextrum.com" target="_blank">Vextrum 
      Studios</a> </div>
  </div>
  <!--end whopper-->
</div>
<!--end centerpage-->

</body>
</html>

[/syntax]
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok, i am working on this page

http://www.mcnealeyprinting.com/test/order.php

and when you click each of the different options, a different forms populates, and at the end of each form, there is an upload form that is supposed to work with each of the different options. The upload script works by itself, but it doesn't work differently with each of the different options. I would like the upload form to upload a file when you click on the business cards option and when you click on the postcard option and other. In the .zip file contains the whole .php file i am using.
There is one form that operates each of the options.

Below is an example of one of the form options and PHP upload:


Code: Select all


<form name="the_form">
		<font style="color:#3399FF">Choose One:</font> 
          <input type="radio" name="form_type" value="ez"
  onClick="switchDiv('ez');">
  			<input type="hidden">
          Business Cards 
          <input type="radio" name="form_type" value="full"
  onClick="switchDiv('full');">
          Postcards 
          <input type="radio" name="form_type" value="full"
  onClick="switchDiv('superduper');">
          Other 
        </form>
        <div id="ez" style="position:absolute;visibility:hidden;top:200px;left:5px;"> 
          <form name="ez_form" method="POST" 
  action="http://64.175.14.218/cgi-bin/thanks.cgi"><br /><br>



            <table>
              <tr> 
                <td>Final Size:</td>
                <td> <select name="final_size">
                    <option value="final_size">3.5" x 2"</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Print Type:</td>
                <td> <select name="print_type">
                    <option value="print_type">--Select Print Type--</option>
                    <option value="1/0">1/0</option>
                    <option value="1/1">1/1</option>
                    <option value="2/0">2/0</option>
                    <option value="2/2">2/2</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Material:</td>
                <td> <select name="material">
                    <option value="material">80PT Cover </option>
                    <option value="material">100 PT Cover</option>
                    <option value="material">10PT</option>
                    <option value="material">12 Pt. Covers C1S</option>
                    <option value="material">Field for Gloss and Non Gloss </option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Gloss:</td>
                <td> <select name="gloss">
                    <option value="gloss">Gloss</option>
                    <option value="gloss">Non-Gloss</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Type of Service:</td>
                <td> <select name="material">
                    <option value="material">24 Hours</option>
                    <option value="material">48 Hours</option>
                    <option value="material">5 days</option>
                  </select> </td>
              <tr> 
              <tr> 
                <td>Format:</td>
                <td> <select name="format">
                    <option value="format">--Select Format--</option>
                    <option value="PDF">PDF</option>
                    <option value="photoshop">Photoshop</option>
                    <option value="illustrator">Illustrator</option>
                    <option value=".TIFF">.TIFF</option>
                    <option value=".EPS">.EPS</option>
                    <option value="quark">QuarkXpress</option>
                    <option value="indesign">Indesign</option>
                    <option value="corel_draw">Corel Draw</option>
                  </select> </td>
              </tr>
              <tr> 
                <td>Quantity:</td>
                <td> <select name="quantity">
                    <option value="quantity">--Select Quantity--</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="1500">1500</option>
                    <option value="2000">2000</option>
                    <option value="2500">2500</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                  </select> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Sub-Total:</strong> </td>
              </tr>
              <tr> 
                <td align="center" colspan="2"> <strong>Total:</strong> </td>
              </tr>
            </table>
          <input type="submit" value="continue">
          </form>




Code: Select all




<?php  

// specify the directory where the uploaded file should end up  
$path = 'upload/' ;  

// specify the filetypes allowed  
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');  

// specify the max filesize in bytes  
$max_size = 200000;  

if(isset($HTTP_POST_FILES['userfile']))  
{  
  if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))  
  {  
   if($HTTP_POST_FILES['userfile']['size'] < $max_size)  
   {  
    if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed))  
    {  
     if(!file_exists($path . $HTTP_POST_FILES['userfile']['name']))  
     {  
      if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name']))  
      {  
       $html_output = 'Upload sucessful!<br>';  
       $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>';  
       $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>';  
       $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br><br>';  
       $html_output .= '<a href="order.php">Back to upload form</a>'; 
       $image = $HTTP_POST_FILES['userfile']['name'] ;  
      }else{  
       $html_output = 'Upload failed!<br>';  
       if(!is_writeable($path))  
       {  
        $html_output = 'The Directory "'.$path.'" must be writeable!<br>';  
        $html_output .= '<a href="order.php">Back to upload form</a>'; 
       }else{  
        $html_output = 'an unknown error ocurred.<br>';   
        $html_output .= '<a href="order.php">Back to upload form</a>';      
       }  
      }  
     }else{  
      $html_output = 'The file already exists<br>'; 
      $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>';  
      $html_output .= '<a href="order.php">Back to upload form</a>';  
     }  
    }else{  
     $html_output = 'Wrong file type<br>';  
     $html_output .= '<a href="order.php">Back to upload form</a>'; 
    }  
   }else{  
    $html_output = 'The file is too big<br>';  
    $html_output .= '<a href="order.php">Back to upload form</a>'; 
   }  
  }  
}else{  
  $html_output = '<TABLE BGCOLOR="#dcdcdc" BORDER="1" bordercolor="#000066" CELLSPACING="2" CELLPADDING="2" WIDTH="30%">'; 
  $html_output .= '<tr><td align="center">'; 
  $html_output .= '<strong><div align="center">Upload File!</div></strong>'; 
  $html_output .= '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';  
  $html_output .= '<input type="file" name="userfile"><br>';  
  $html_output .= '<input type="submit" value="upload">';  
  $html_output .= '</form>';  
  $html_output .= '</td></tr></table>'; 

}  

echo $html_output;        

?> 



User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Mike, Mike, MIke ... can you ask a question more specific than " I would like the upload form to upload a file when you click on the business cards option and when you click on the postcard option and other. " and narrow down the problem and section of code a little -- that's a lot to wade through for volunteers.
(#10850)
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

It' s hard to understand want you need. At first glance the code seems fine.
Search with Google or on [url]www.tutorialized.com[/com] for PHP upload files, you' ll find some very good ones or if you need just the code search phpclasses.org.
If you want to have different events for the each type of card rename the radio buttons (radio_bussines), make different functions or a function that deals with the options selected or a class and in the PHP code put

Code: Select all

if (isset($_POST['radio_bussines']))
{
    upload_function_bussines($picture);
}
else if (isset($_POST['radio_card']))
{
   upload_function_card($picture, $option_1, $option_2);
}
Hope that it will help you
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok that does help out, but what would go in each of the functions?, i know it would deal with the options selected, but how can i get php to do that? what php code would go in each of the functions?
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok, new question:
i am still working with the same file and code, but on one page i have the forms, then i created another PHP page to thank the user and display the information from the form and to display the contents of the file that has been uploaded.
The php page that i'm trying to display the information doesn't work, and im not sure why. am i calling the wrong variable to display the information? how do you display the contents of the upload script and field on the next php page?
all of the code i am using and the php upload script is provided above.
what i've tried to do so far to display the information is

echo $html_output;

When i tried that, the results are nothing, nothing shows up, nothing is displayed.

by looking at the code, is there some other way to echo out the contents on another php page?
thanks
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

The easiest way is to put the values into some super global variables like session vaiables, post variables. If you dump all the contents into some hidden field or into some session variables and get that value on another page though POST or SESSION variable, your problem is solved.

Looking at code you have concatenated all the html output into one vaiable. Put the final variable output into either hidden field or into some session variable.

Hope that solves your problem.
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok, so how would i put all of the values into session variables? and how would i get the value through a POST variable? would i use a form to carry it to another page?

also, would i put all of the HTML including all of the forms into one variable? then how would i put that final variable output into a hidden field or session variable?
thanks
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok, new question:
i am working with IF ELSE statements, im trying to get the information to display on the PHP page, but when i have one if statement and have an elseif in there, the variables from the elseif don't show up from the form. They show up in the first if statement, but not in the else if statments. can you help me in getting the ECHO's to work in the elseif statements to show up on the php page.

This is the code that i have, and it seems right, but the echo's aren't showing up for some reason and i would like the results to display.
thanks

Code: Select all


 if ($name ==  $_POST["name"] || $cname ==  $_POST["cname"] || $user_email ==  $_POST["user_email"] || $phone ==  $_POST["phone"] || $fax ==  $_POST["fax"] || $yes ==  $_POST["yes"] || $final_size == $_POST["final_size"] || $print_type == $_POST["print_type"] || $material == $_POST["material"] || $gloss == $_POST["gloss"] || $service == $_POST["service"] || $format == $_POST["format"]) 
{ 
echo "<strong>FORM 1 - BUSINESS CARDS</strong><br><br>"; 
echo "Name: $name<br>"; 
echo "Company Name: $cname<br>"; 
echo "Email: $user_email<br>"; 
echo "Phone Number: $phone<br>"; 
echo "Fax: $fax<br>"; 
echo "Is this the file: $yes<br>";     
echo "Final Size: $final_size<br>"; 
echo "Print Type: $print_type<br>"; 
echo "Material: $material<br>"; 
echo "Gloss: $gloss<br>"; 
echo "Service: $service<br>"; 
echo "Format: $format<br>"; 
echo "Quantity: $quantity<br><br>"; 
} 
elseif ($name2 ==  $_POST["name2"] || $cname2 ==  $_POST["cname2"] || $user_email_2 ==  $_POST["user_email_2"] || $phone2 ==  $_POST["phone2"] || $fax2 ==  $_POST["fax2"] || $yes2 ==  $_POST["yes2"] || $final_size_post == $_POST["final_size_post"] || $print_type2 == $_POST["print_type2"] || $material2 == $_POST["material2"] || $service2 == $_POST["service2"] || $format2 == $_POST["format2"] || $quantity2 == $_POST["quantity2"]) 
{ 
echo "<strong>FORM 2 - POSTCARDS</strong><br><br>"; 
echo "Name: $name2<br>"; 
echo "Company Name: $cname2<br>"; 
echo "Email: $user_email_2<br>"; 
echo "Phone Number: $phone2<br>"; 
echo "Fax: $fax2<br>"; 
echo "Is this the file: $yes2<br>"; 
echo "Final Size: $final_size_post<br>"; 
echo "Print Type: $print_type2<br>"; 
echo "Material: $material2<br>"; 
echo "Service: $service2<br>"; 
echo "Format: $format2<br>"; 
echo "Quantity: $quantity2<br><br>"; 
} 
else 
{ 
echo "DOES NOT WORK"; 
}  



User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

For debugging using time saving techniques will be to see if the variables are set or not by printing the POST variables.

Code: Select all

print_r($_POST);
OR

Code: Select all

var_dump($_POST);
if they are not set for if else block, then there is some problem in your form or something else.

With regards,
Dibyendra
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

ok, i have my ifelse statements like posted above and the results come out to be

Name: 1
Company Name: 1
Email: 1
Phone Number: 1
Fax: 1
Is this the file: 1
Final Size: 1
Print Type: 1
Material: 1
Service: 1
Format: 1
Quantity: 1500

I was wondering why I am getting the result of 1? and how can i get the results to display correctly? i have not entered 1 in any fields, all i have entered is text.

also, i tried print_r($_POST);
and the results come out to be:
Array ( [name2] => asdf [cname2] => asdf [user_email_2] => asdf@zsdf.gff [phone2] => dfg [fax2] => sdfg [final_size_post] => 5x7 [print_type2] => 4/1 [material2] => 10 Pt. Covers C1S [service2] => 48 Hours [format2] => illustrator [quantity2] => 1500 [yes2] => yes )

also i tried var_dump($_POST);
and these are the results:
array(12) { ["name2"]=> string(4) "asdf" ["cname2"]=> string(4) "asdf" ["user_email_2"]=> string(13) "asdf@zsdf.gff" ["phone2"]=> string(3) "dfg" ["fax2"]=> string(4) "sdfg" ["final_size_post"]=> string(3) "5x7" ["print_type2"]=> string(3) "4/1" ["material2"]=> string(17) "10 Pt. Covers C1S" ["service2"]=> string(8) "48 Hours" ["format2"]=> string(11) "illustrator" ["quantity2"]=> string(4) "1500" ["yes2"]=> string(3) "yes" }

also, i have a 3rd option with an 3rd ifelse statement and when i run that test on the php page, the results come up to be "does not work". it does not display the results on the 3rd option on the 3rd ifelse statement. why? and can you help me in getting this to display?

i think the variables are set correctly, but what else could be wrong? please help me solve this and get this information to display correctly.
thanks
Below is the full ifelse statement code i am using:

Code: Select all


if ($name =  $_POST["name"] && $cname =  $_POST["cname"] && $user_email =  $_POST["user_email"] && $phone =  $_POST["phone"] && $fax =  $_POST["fax"] && $yes =  $_POST["yes"] && $final_size = $_POST["final_size"] && $print_type = $_POST["print_type"] && $material = $_POST["material"] && $gloss = $_POST["gloss"] && $service = $_POST["service"] && $format = $_POST["format"])
{
echo "<strong>FORM 1 - BUSINESS CARDS</strong><br><br>";
echo "Name: $name<br>";
echo "Company Name: $cname<br>";
echo "Email: $user_email<br>";
echo "Phone Number: $phone<br>";
echo "Fax: $fax<br>";
echo "Is this the file: $yes<br>";	
echo "Final Size: $final_size<br>";
echo "Print Type: $print_type<br>";
echo "Material: $material<br>";
echo "Gloss: $gloss<br>";
echo "Service: $service<br>";
echo "Format: $format<br>";
echo "Quantity: $quantity<br><br>";
}
elseif ($name2 =  $_POST["name2"] && $cname2 =  $_POST["cname2"] && $user_email_2 =  $_POST["user_email_2"] && $phone2 =  $_POST["phone2"] && $fax2 =  $_POST["fax2"] && $yes2 =  $_POST["yes2"] && $final_size_post = $_POST["final_size_post"] && $print_type2 = $_POST["print_type2"] && $material2 = $_POST["material2"] && $service2 = $_POST["service2"] && $format2 = $_POST["format2"] && $quantity2 = $_POST["quantity2"])
{
echo "<strong>FORM 2 - POSTCARDS</strong><br><br>";
echo "Name: $name2<br>";
echo "Company Name: $cname2<br>";
echo "Email: $user_email_2<br>";
echo "Phone Number: $phone2<br>";
echo "Fax: $fax2<br>";
echo "Is this the file: $yes2<br>";
echo "Final Size: $final_size_post<br>";
echo "Print Type: $print_type2<br>";
echo "Material: $material2<br>";
echo "Service: $service2<br>";
echo "Format: $format2<br>";
echo "Quantity: $quantity2<br><br>";
}
elseif ($name3 =  $_POST["name3"] && $cname3 =  $_POST["cname3"] && $user_email3 =  $_POST["user_email3"] && $phone3 =  $_POST["phone3"] && $fax3 =  $_POST["fax3"] && $yes3 =  $_POST["yes3"] && $final_size3 = $_POST["final_size3"] && $print_type3 = $_POST["print_type3"] && $material3 = $_POST["material3"] && $gloss3 = $_POST["gloss3"] && $service3 = $_POST["service3"] && $format3 = $_POST["format3"] && $quantity3 = $_POST["quantity3"])
{
echo "<strong>FORM 3 - OTHER</strong><br><br>";
echo "Name: $name3<br>";
echo "Company Name: $cname3<br>";
echo "Email: $user_email3<br>";
echo "Phone Number: $phone3<br>";
echo "Fax: $fax3<br>";
echo "Is this the file: $yes3<br>";
echo "Final Size: $final_size_post3<br>";
echo "Print Type: $print_type3<br>";
echo "Material: $material3<br>";
echo "Gloss: $gloss3<br>";
echo "Service: $service3<br>";
echo "Format: $format3<br>";
echo "Quantity: $quantity3<br><br>";
}
else
{
echo "DOES NOT WORK";
}

mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

can anyone help me out with this to why 1's are showing up instead of the results?
i would like the results to show up, can anyone help me in getting this to work?
thanks
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Sorry that I couldn't reply soon.
It seems confusing looking at your result. At the printing of POST variable, it seems only the second elseif condition is executed. Will you please tell us when do the results come as 1 and when do the elseif branch is executed ? Looking at your code, you have placed all the conditions in if and else conditions. To make the code easy to read, there should be only a certain conditions like :

Code: Select all

$card_type = $_POST["card_type"];

if($card_type == "postcard"){
    //do for postcard
}elseif($card_type == "businesscard"){
    //do for business card
}
When you add all the conditions and take the values while checking the conditions, it makes your code clumsy as well as very hard to modify and debug. So, please add certain hidden values to the form or some other mechanism so that you don't have to put so many conditions in condition branch.

Hope that you've got an idea now.

Dibyendra
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

The results come back as one after i have entered information into the form and see the results on the next php page. Im guessing the elseif branch is executed after i click the submit button and before i view the results?
above my conditions, i do have each of the variables set, for example: $name = $_POST["name"];
ok, should i narrow my code down to look more like this???

Code: Select all

$name1 = $_POST["name1"];
$cname = $_POST["cname"];

if ($name1 = $_POST["name1"])
{
echo "$name1";
}
elseif ($cname = $_POST["cname"])
{
echo "$cname";
}
//and so on....
else
{
echo "DOES NOT WORK";
}

also, would I have to add hidden values to all of my form fields?
would i echo out like above or like this: echo "$_POST['name']";

also in my file upload php script, in the $_FILES array, could i have something like this and have only one upload script?

Code: Select all

$HTTP_POST_FILES['userfile1, userfile2, userfile3']['name'] 
/*and so on...*/ 
please let me know
thanks
mikewooten
Forum Contributor
Posts: 169
Joined: Wed Feb 11, 2004 12:13 pm
Location: Duluth, Georgia
Contact:

Post by mikewooten »

can someone help me out with this???
thanks
Post Reply