Advertisement

10.20.2006 at 03:02PM PDT, ID: 22032592
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Why doesn't my File Upload form work properly?

Asked by bloodtrain in PHP Scripting Language

Tags: , ,

Hi..

I have a form with some text fields and a file field. When I try uploading files, I get my "No File Selected" for some files and other file uploads work fine. All files that I'm testing with have been less than 100k.

Can you please take a look at my code and let me know what I can improve/change.

Thanks.




<?php
include("includes/main.php");
mysql_connect ($db_hostname, $db_username, $db_password) or die ("Error locating database. Please try again later.");
mysql_select_db($db_name) or die ("Unable to connect to the database. Please try again later.");

$var_errornum = 0;
$var_errormsg = "";
$maxfilesize = 10485760;

if(isset($_REQUEST["txt_firsttime"]) == "no"){

      $var_fname = $_REQUEST["txt_fname"];
      $var_lname = $_REQUEST["txt_lname"];
      $var_company = $_REQUEST["txt_company"];
      $var_address = $_REQUEST["txt_address"];
      $var_city = $_REQUEST["txt_city"];
      $var_province = $_REQUEST["txt_province"];
      $var_country = $_REQUEST["txt_country"];
      $var_postal = strtoupper($_REQUEST["txt_postal"]);
      $var_phone = $_REQUEST["txt_phone"];
      $var_ext = $_REQUEST["txt_ext"];
      $var_email = $_REQUEST["txt_email"];
      $var_type = $_REQUEST["sel_type"];
      $var_material = $_REQUEST["txt_material"];
      $var_resolution = $_REQUEST["sel_resolution"];
      $var_color = $_REQUEST["sel_color"];
      $var_comments = $_REQUEST["txt_comments"];
      $var_datetime = date("Y-m-d H:i:s");


      if(strlen($var_fname) == 0){
            $var_errornum = 1;
            $var_errormsg = "First name is required. Please enter your first name.";
      } elseif(strlen($var_lname) == 0){
            $var_errornum = 1;
            $var_errormsg = "Last name is required. Please enter your last name.";
      } elseif(strlen($var_address) == 0){
            $var_errornum = 1;
            $var_errormsg = "Address is required. Please enter your address.";
      } elseif(strlen($var_city) == 0){
            $var_errornum = 1;
            $var_errormsg = "City is required. Please enter your city.";
      } elseif(strlen($var_province) == 0){
            $var_errornum = 1;
            $var_errormsg = "Province is required. Please enter your province.";
      } elseif(strlen($var_country) == 0){
            $var_errornum = 1;
            $var_errormsg = "Country is required. Please enter your country.";
      } elseif(strlen($var_postal) == 0){
            $var_errornum = 1;
            $var_errormsg = "Postal code is required. Please enter your postal code.";
      } elseif(strlen($var_phone) == 0){
            $var_errornum = 1;
            $var_errormsg = "Phone number is required. Please enter your phone number.";
      } elseif(strlen($var_email) == 0){
            $var_errornum = 1;
            $var_errormsg = "Email address is required. Please enter your valid email address.";
      } elseif(!eregi('^[a-z0-9._-]+@[a-z0-9._-]+\.([a-z]{2,4})$', $var_email)){
            $var_errornum = 1;
            $var_errormsg = "The email address you entered contains invalid character(s) and/or wrong format.";      
      } elseif (!is_uploaded_file($HTTP_POST_FILES['myfile']['tmp_name'])) {
            $var_errornum = 1;
            $var_errormsg = "NO FILE WAS SELECTED FOR UPLOAD!<br>Please click on <i>Browse</i> and select your CAD document from your hard drive.";
            unlink($HTTP_POST_FILES['myfile']['tmp_name']);
      } elseif ($HTTP_POST_FILES['myfile']['size'] > $maxfilesize) {
            $var_errornum = 1;
            $var_errormsg = "File is too large. Try compressing (zipping) your file and then uploading it.";
            unlink($HTTP_POST_FILES['myfile']['tmp_name']);
      }
      
      if($var_errornum == 0){

            $result = mysql_query("INSERT INTO tbl_quotes (quote_fname, quote_lname, quote_company, quote_address, quote_city, quote_province, quote_country, quote_postal, quote_phone, quote_ext, quote_email, quote_type, quote_material, quote_resolution, quote_color, quote_comments, quote_datetime) VALUES ('$var_fname', '$var_lname', '$var_company', '$var_address', '$var_city', '$var_province', '$var_country', '$var_postal', '$var_phone', '$var_ext', '$var_email', '$var_type', '$var_material', '$var_resolution', '$var_color', '$var_comments', '$var_datetime')") OR die("There has been an expected error. Please try again.".mysql_error());
            $var_autonumber = mysql_insert_id();
            $uploaddir = "content/quotes/";
            $uploadfile = $uploaddir . basename($_FILES['myfile']['name']);
            
            if (move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile))
            {
                  echo "File is valid, and was successfully uploaded.\n";
            } else {
                  echo "Possible file upload attack!\n";
            }
            echo 'Here is some more debugging info:';
            print_r($_FILES);
      }

}
else
{
      $var_fname = "";
      $var_lname = "";
      $var_company = "";
      $var_address = "";
      $var_city = "";
      $var_province = "";
      $var_country = "";
      $var_postal = "";
      $var_phone = "";
      $var_ext = "";
      $var_email = "";
      $var_type = 0;
      $var_material = "";
      $var_resolution = 1;
      $var_color = 0;
      $var_comments = "";

}

// SQL QUERY FOR MAIN MENU
$query = "SELECT * FROM tbl_content WHERE content_menu = 1 AND content_visible = 1 ORDER BY content_sortorder";
$rsmenu = mysql_query($query) or die("The query failed. ".mysql_error());
$num_rsmenu = mysql_num_rows($rsmenu);

$var_passedid = 5;
$query = "SELECT * FROM tbl_content WHERE content_id = $var_passedid AND content_visible = 1 ORDER BY content_sortorder";
$rscontent = mysql_query($query) or die("The query failed. ".mysql_error());
$num_rscontent = mysql_num_rows($rscontent);
if($num_rscontent == 0){ header("Location: index.php?id=0"); }

while ($row = mysql_fetch_array($rscontent)){
      $var_contentid = $row["content_id"];
      $var_pagetitle = $row["content_pagetitle_" . $main__lang];
      $var_content = $row["content_" . $main__lang];
      $var_image = $row["content_image"];
}


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php print $main__title; ?>
<?php if($var_pagetitle != ""){ print " | " . $var_pagetitle; } ?>
</title>
<link href="/includes/main.css" rel="stylesheet" type="text/css">
<script language="javascript">
<!--
function toggletype() {

      if ( document.getElementById("sel_type").options[document.getElementById("sel_type").options.selectedIndex].value == "0" ) {
         document.getElementById('machined1').style.display = '';
         document.getElementById('machined2').style.display = '';
         document.getElementById('prototyped').style.display = "none";
      } else {
         document.getElementById('prototyped').style.display = '';
         document.getElementById('machined1').style.display = "none";
         document.getElementById('machined2').style.display = "none";
      }
}

//-->
</script>
</head>

<body onLoad="toggletype();">
<form name="frm" method="post" enctype="multipart/form-data" action="quote.php">
<?php include("includes/header.php"); ?>
<table width="708" border="0" align="center" cellpadding="0" cellspacing="0" id="canvas">
  <tr>
    <td><img src="/content/banners/<?php if($var_image == 1){ print $var_contentid; } else { print "0"; } ?>.jpg" width="700" height="216"><br>
        <table width="700" border="0" cellpadding="0" cellspacing="0" id="menu">
        <tr>
<?php
$var_ctr = 1;
while ($row = mysql_fetch_array($rsmenu)){
?>
          <td align="center"><a href="<?php if($row["content_url"] != ""){ print  $row["content_url"]; } else { print "/index.php?id=" . $row["content_id"]; } ?>" class="menuitem"><?php print $row["content_menutitle_" . $main__lang]; ?></a></td>
      <?php if($var_ctr < $num_rsmenu){ ?>
              <td width="6"><img src="/images/divider.gif" width="6" height="50"></td>
      <?php } ?>

<?php
$var_ctr += 1;
}
?>
        </tr>
      </table>
        <br>
        <table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="415"><?php if($var_pagetitle != "") { ?><span class="pagetitle"><?php print $var_pagetitle; ?></span><?php } ?><br><br>
            <table width="400" border="0" cellspacing="0" cellpadding="0">
<?php if($var_errornum == 1){ ?>            
                  <tr>
                  <td colspan="2"><table width="360"><tr><td style="border: 1px dashed #990000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; background-color:#C00101; color:#FFFFFF; padding: 5px"><?php print $var_errormsg; ?></td></tr></table></td>
                  </tr>
                  <tr><td>&nbsp;</td></tr>
<?php } ?>
              <tr>
                <td width="200" class="form_header" style="padding-bottom: 10px">First name*<br>
                    <input name="txt_fname" type="text" class="form_textbox" style="width: 150px" maxlength="40" value="<?php print $var_fname; ?>"></td>
                <td width="194" class="form_header" style="padding-bottom: 10px">Last name*<br>
                    <input name="txt_lname" type="text" class="form_textbox" style="width: 150px" maxlength="50" value="<?php print $var_lname; ?>"></td>
              </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Company name<br>
                    <input name="txt_company" type="text" class="form_textbox" style="width: 150px" maxlength="50" value="<?php print $var_company; ?>"></td>
              </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Address*<br>
                    <input name="txt_address" type="text" class="form_textbox" style="width: 352px" maxlength="200" value="<?php print $var_address; ?>"></td>
              </tr>
              <tr>
                <td class="form_header" style="padding-bottom: 10px">City*<br>
                    <input name="txt_city" type="text" class="form_textbox" style="width: 150px" maxlength="50" value="<?php print $var_city; ?>"></td>
                <td class="form_header" style="padding-bottom: 10px">Province*<br>
                    <input name="txt_province" type="text" class="form_textbox" style="width: 150px" maxlength="50" value="<?php print $var_province; ?>"></td>
              </tr>
              <tr>
                <td class="form_header" style="padding-bottom: 10px">Country*<br>
                    <input name="txt_country" type="text" class="form_textbox" style="width: 150px" maxlength="50" value="<?php print $var_country; ?>"></td>
                <td class="form_header" style="padding-bottom: 10px">Postal code*<br>
                    <input name="txt_postal" type="text" class="form_textbox" style="width: 150px" maxlength="7" value="<?php print $var_postal; ?>"></td>
              </tr>
              <tr>
                <td class="form_header" style="padding-bottom: 10px">Phone number* (555-555-5555)<br>
                    <input name="txt_phone" type="text" class="form_textbox" style="width: 150px" maxlength="12" value="<?php print $var_phone; ?>"></td>
                <td class="form_header" style="padding-bottom: 10px">Extension<br>
                    <input name="txt_ext" type="text" class="form_textbox" style="width: 150px" maxlength="5" value="<?php print $var_ext; ?>"></td>
              </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Email address*<br>
                    <input name="txt_email" type="text" class="form_textbox" style="width: 352px" maxlength="200" value="<?php print $var_email; ?>"></td>
              </tr>
                    <tr>
                        <td colspan="2" style="padding-top: 15px; padding-bottom: 15px "><img src="images/bluedot.gif" width="356" height="1"></td>
                    </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Project type<br><select name="sel_type" id="sel_type" class="form_textbox" style="width: 356px" onChange="toggletype();">
                  <option value="0" <?php if($var_type == 0){ print "selected"; } ?>>Machined</option>
                  <option value="1" <?php if($var_type == 1){ print "selected"; } ?>>Rapid Prototyped</option>
                </select></td>
              </tr>
              <tr id="prototyped">
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Material*<br>
                    <input name="txt_material" type="text" class="form_textbox" style="width: 352px" maxlength="50" value="<?php print $var_material; ?>"></td>
              </tr>
              <tr id="machined1">
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Resolution<br><select name="sel_resolution" class="form_textbox" style="width: 356px">
                  <option value="0" <?php if($var_resolution == 0){ print "selected"; } ?>>Low</option>
                  <option value="1" <?php if($var_resolution == 1){ print "selected"; } ?>>High (Default)</option>
                </select></td>
              </tr>
              <tr id="machined2">
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Color<br><select name="sel_color" class="form_textbox" style="width: 356px">
                  <option value="0" <?php if($var_color == 0){ print "selected"; } ?>>White (Default)</option>
                  <option value="1" <?php if($var_color == 1){ print "selected"; } ?>>Color (Extra charge may apply)</option>
                </select></td>
              </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Comments<br>
                    <textarea name="txt_comments" rows="5" wrap="virtual" class="form_textbox" style="width: 352px"><?php print $var_comments; ?></textarea></td>
              </tr>
              <tr>
                <td colspan="2" class="form_header" style="padding-bottom: 10px">Attach a file* | <span class="form_value">Allowed file types: .stl, .prt, .igs (solid)</span><br>
                    <input type="hidden" name="MAX_FILE_SIZE" value="10485760">
                              <input name="myfile" type="file" class="form_textbox" style="width: 356px"></td>
              </tr>
              <tr>
                <td colspan="2" class="form_button"><br>
                    <a href="javascript:document.frm.submit();" class="form_button">SEND</a>&nbsp;<a href="javascript:document.frm.reset();" class="form_button">CLEAR</a></td>
              </tr>
            </table>
              </td>
          <td width="265" valign="top"><span class="content"><?php print $var_content; ?></span></td>
        </tr>
      </table>
        <br>
      <br>
      </td>
  </tr>
</table>
<table width="708" border="0" align="center" cellpadding="0" cellspacing="0" id="canvasfooter">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<?php include("includes/footer.php"); ?>
<input name="txt_firsttime" type="hidden" value="no">
</form>
</body>
</html>Start Free Trial
[+][-]10.20.2006 at 03:18PM PDT, ID: 17777695

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.21.2006 at 08:23AM PDT, ID: 17780566

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.21.2006 at 07:02PM PDT, ID: 17782445

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.22.2006 at 05:36AM PDT, ID: 17783624

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: file, php, javascript
Sign Up Now!
Solution Provided By: keslan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.23.2006 at 08:30AM PDT, ID: 17789231

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.23.2006 at 04:40PM PDT, ID: 17792456

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.23.2006 at 09:22PM PDT, ID: 17793470

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.23.2006 at 09:51PM PDT, ID: 17793534

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.24.2006 at 05:22AM PDT, ID: 17795069

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.24.2006 at 05:24AM PDT, ID: 17795081

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.24.2006 at 08:07AM PDT, ID: 17796421

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.24.2006 at 09:43AM PDT, ID: 17797254

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 03:01AM PST, ID: 17963979

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32