Upload-File echo(Display Message);

I’m trying to create a form that will allow the user to upload a image to an email address, rather then a /directory/ on my server. Here is the form that i’m working with.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
  // define category array
  $aCategories = array(
    0 => "Categories",
    1 => "HTML",
    2 => "CSS",
    3 => "Wordpress",
    4 => "Javascript",
    5 => "Examples of code",
    6 => "Web Development",
    7 => "PSD > HTML & CSS"
  ); 

 
  // initialize form variables
  $cleanName = '';
  $cleanEmail = '';
  $cleanWebsite = 'http://';
  $cleanCategory = 0;
  $cleanComments = '';
  $cleanCity = '';
 
  // if form has been submitted, check all user input
  // if everything is ok, submit the mail
  if  ($_SERVER['REQUEST_METHOD']=="POST") {
   
    // initialize error array
    $aErrors = array();
 
    // check name
    if (isset($_POST['name']) && '' != trim($_POST['name'])) {
      $cleanName = trim($_POST['name']);
    } else {
      $aErrors['name'] = 'You must insert a name';
    }
 
    // check email
    if (isset($_POST['email']) && '' != trim($_POST['email'])) {
      $cleanEmail = trim($_POST['email']);
      // HERE YOU COULD/SHOULD ADD ANOTHER CHECK TO SEE IF THE
      // EMAIL ADDRESS IS VALID. DO A SEARCH FOR 'EMAIL REGEX' OR
      // SOMETHING LIKE THAT TO FIND EXAMPLES
    } else {
      $aErrors['email'] = 'You must insert an email';
    }
 
    // check website (are you sure this is a field they MUST fill out ?)
    if (isset($_POST['website']) && '' != trim($_POST['website'])) {
      $cleanWebsite = trim($_POST['website']);
    } else {
      $aErrors['website'] = 'You must insert a website';
    }
 
    // check comments
    if (isset($_POST['comments']) && '' != trim($_POST['comments'])) {
      $cleanComments = trim($_POST['comments']);
    } else {
      $aErrors['comments'] = 'You must insert a comment';
    }
 
    // check category
    if (isset($_POST['category']) && 0 != (int)$_POST['category']) {
      $cleanCategory = (int)$_POST['category'];
      if (!array_key_exists($cleanCategory, $aCategories))  {
        $aErrors['category'] = 'You must choose a valid category';
      }
    } else {
      $aErrors['category'] = 'You must choose a category';
    }
 
    if (is_numeric($_POST['city']) && 0 == count($aErrors)) {
      $message = "Name: $cleanName\
";
      $message.= "Email: $cleanEmail\
";
      $message.= "Website: $cleanWebsite\
";
      $message.= "Comments: $cleanComments\
";
      $message.= "Dropdown: " . $aCategories[$cleanCategory] . "\
";
      mail("blake@cssispoetry.com", "Work", $message);
      exit();
 
    }
  }
 

?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="content-language" content="en" />
        <title>CSSispoetry | Contact Us</title>
        <link href="contact_us.css" rel="stylesheet" type="text/css" media="screen" />
    <!--[if IE 6]><link rel="stylesheet" type="text/css" href="iespecific.css" /><![endif]-->
    <!--[if IE 7]><link href="ie7_styles.css" rel="stylesheet" type="text/css"><![endif]-->

    <script src="pngFixer.js" type="text/javascript"></script>
        <script src="pngFixer.js" type="text/javascript"></script>
        <script type="text/javascript">
        window.onload = function() {
        pngFixer.path('http://www.cssispoetry.com/live/images/blank.gif');
        pngFixer.init('img, div, body, li, h1, h2, h3, h4, h5, span');
        }
    </script>
    </head>
    <body>
        <!--The start of the markup-->
        <div id="container">

            <div id="top_header">
                <h1>
                    <a href="#">CSSispoetry</a>
                </h1>
                <ul>
                    <li>
                        <a href="">Home</a>

                    </li>
                    <li>
                        <a href="">About</a>
                    </li>
                    <li>
                        <a href="">Services</a>
                    </li>
                    <li>

                        <a href="">Portfolio</a>
                    </li>
                    <li>
                        <a href="">Code Blog</a>
                    </li>
                    <li>
                        <a href="">Contact Us</a>

                    </li>
                </ul><!-- The end of top_header list-->
            </div><!-- The end of top_header-->
            <div id="top_section">
                <div id="top_section_inner_left">
                    <h3 class="innerleft">
                        Latest Blog Post
                    </h3><img src="http://cssispoetry.com/live/images/latest_post.jpg" class="insideimage" alt="Latest_Post" />
                    <p class="text">

                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. egestas erat nec dui vulputate sagittis vel et sem. Phasellus
                        pretium orci vitae lorem venenatis ultricies.
                    </p><a href="" class="readmore">Read More..</a>
                </div>
                <div id="top_section_inner_right">
                    <p class="intro">
                        "A group of kids that want to

                        make an impact on the web!"
                    </p><a href="#">Hire Us</a>

                </div><!--The end of top_section_inner_right-->

            </div><!--The end of top_section-->
            <div id="middle_section">
                <div id="middle_section_inner">
                    <h2>
                        Contact Us
                    </h2>
                    <div id="middle_section_inner_content">
                        <p>

                            
                            

Had a look at our portfolio and are interested in the services we provide? Want to find out more about the people behind CSSispoetry? Whatever your reason for contact just fill out the form below and we will get back to you as quickly as possible.
                        </p>
                        <form method="post" action="contact_us.php">
                            <span class="form_names">Name:</span><br />
                            <input name="name" class="contact_form" type="text" value="<?php echo $cleanName; ?>" /><br />
                            <span class="form_names">Email Address:</span><br />
                            <input name="email" class="contact_form" type="text" value="<?php echo $cleanEmail; ?>" /><br />
                            <span class="form_names">Your Website:</span><br />

                            <input name="website" class="contact_form" type="text" value="<?php echo $cleanWebsite; ?>" /><br />
                            <span class="form_names">Please choose a Category.</span> <select id="dropdown" name="category">
                                <?php
                                                                                                    // add options from category array
                                                                                                    foreach ($aCategories as $key => $value) {
                                                                                                      $selected = ($key == $cleanCategory) ? 'selected = "selected"': '';
                                                                                                ?>
                                <option value="<?php echo $key; ?>">
                                    <?php echo $value; ?>
                                </option><?php     
                                                                                                    }
                                                                                                ?>
                            </select><br />

                            <span class="form_names">Your Message:</span><br />

                            <textarea name="comments" rows="16">
                              
                            <?php echo $cleanComments; ?>
                                                       
                                                       
                            </textarea><br />
                            <span class="form_names">What does 5 + 5=?</span><br />
                            <input name="city" class="contact_form" type="text" value="<?php echo $cleanCity; ?>" /><br />
                            <input type="submit" id="submit" value="Submit" /><br />
                        </form><!--The end of the form-->
                    </div><!--The end of middle_section_inner_content-->

                    <div id="contacting">
                        <h2 class="info">

                            Contact Info
                        </h2>
                        <p>
                            CSSispoetry LLC,
                        </p>
                        <p>
                            Cuyahoga Falls, O.H, 44221
                        </p>

                        <p>
                            Phone -
                        
                        +1 (330) 431 0948
                        </p>
                        <p>
                            Hours of Operation 8:00am - 5:00pm M-F
                        </p>
                    
                        <img src="http://cssispoetry.com/live/images/email.ico"><a href="">Email Us</a>
                    </div><!--The end of contacting-->
                    <div id="social_networking">

                        <h2 class="info">
                             Networking
                        </h2>
                        <img src="http://cssispoetry.com/live/images/google_talk.png"><img src="http://cssispoetry.com/live/images/skype.png"><img src="http://cssispoetry.com/live/images/AIM.png">
                        <p>

                            AIM - CSSispoetry
                        </p>
                    
                        <p>
                           Skype -
                           [email]Team@CSSispoetry.com[/email] 
                           (Camera & Voice compatible)
                        </p>

                        
                        
                        <p>
                        
                        Google Wave - Team.cssispoetry                        
                        </p>
                        
                    </div><!--The end of social_networking-->
                    <div id="map">

                        <iframe width="340" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src=
                        "http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=+cuyahoga+falls&amp;sll=41.151774,-81.494608&amp;sspn=0.038518,0.090895&amp;ie=UTF8&amp;hq=&amp;hnear=Cuyahoga+Falls,+Summit,+Ohio&amp;ll=41.197257,-81.450577&amp;spn=0.308556,0.727158&amp;z=11&amp;iwloc=A&amp;output=embed">
                        </iframe><br />
                        <a href=
                        "http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=+cuyahoga+falls&amp;sll=41.151774,-81.494608&amp;sspn=0.038518,0.090895&amp;ie=UTF8&amp;hq=&amp;hnear=Cuyahoga+Falls,+Summit,+Ohio&amp;ll=41.197257,-81.450577&amp;spn=0.308556,0.727158&amp;z=11&amp;iwloc=A"
                        class="c1"></a>
                    </div><!--The end of map-->

                    <div id="payment_processing2">
                        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                            <input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value=
                            "blaketallos@gmail.com" /><input type="hidden" name="lc" value="US" /><input type="hidden" name="item_name" value=
                            "PSD>Conversions, Web development, Graphic Design Services, Programming" /><input type="hidden" name="amount" value=
                            "25.00" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="button_subtype" value=
                            "services" /><input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" /><input type="image"
                            src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt=
                            "PayPal - The safer, easier way to pay online!" /><img alt="" border="0" src=
                            "https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
                        </form>
                    </div>
                    <div id="clearer"></div>
                </div><!--The end of middle_section-->
                <div id="footer_section">
                    <div id="footer_inner">

                        <div id="valid_images">
                        <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt=
                        "Valid XHTML 1.0 Strict" height="31" width="88" /></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img style=
                        "border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /></a>
                        </div>
                        <p>
                            Powered by our own proprietary PHP Framework <a href="#" class="rinse">Rinse</a>
                        </p>
                        <p>

                            Copyright &copy; 2009 CSSispoetry All rights reserved. <a href="" class="rinse">Contact Us</a>

                        </p>
                    </div>
                </div><!--The end of footer_inner-->
            </div><!--The end of footer_section-->
        </div><!--The end of container-->

        <!--The end of the document-->
    </body>
</html>

Here is the form i’m trying to use to upload the file -

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

The other thing I’m trying to do is, create a message that will appear below the form to tell the user if they submitted all of the forms correctly if not display a message saying “please fill all forms in correctly”. I assume this can be done using echo?

It seems like it’s pretty easy for a user to come up with a name and put it in the form and press send and I get filled with a bunch of spam. I tried creating something like this to not let do that it didn’t work.

Can anybody help me?


 function isValidEmail($address) { 
      if (filter_var($address,FILTER_VALIDATE_EMAIL)==FALSE) { 
           return false; 
      } 
      /* explode out local and domain */ 
      list($local,$domain)=explode('@',$address); 
       
      $localLength=strlen($local); 
      $domainLength=strlen($domain); 
       
      return ( 
           /* check for proper lengths */ 
           ($localLength>0 && $localLength<65) && 
           ($domainLength>3 && $domainLength<256) && 
           ( 
                checkdnsrr($domain,'MX') || 
                checkdnsrr($domain,'A') 
           ) 
      ); 
 }