Results 1 to 2 of 2

Thread: Uploading Images for Form Submission

  1. #1

    Uploading Images for Form Submission

    Hi everyone. I have a bit of an issue. I'm the admin / creator of blackoutpoetry.com and I'm trying to enable users to upload images. I've looked all over the web and found a few useful scripts for uploading, but I'm having a problem maintaining the functionality of the rest of my form. Here is the code I'm starting with.

    Form: (found at blackoutpoetry.com/submit.php)
    Code:
    <form method="post" action="sendmail.php" name="msgform">
         <p>
             <label>Name:
               <input type="text" name="name" id="name" />
             </label>
             &nbsp;
             <label>Email:
               <input type="text" name="email" id="email" />
             </label>
         </p>
           <p>
             <label>Where ya from?:
               <input type="text" name="location" id="location" />
             </label>
           </p>
           <p>
             <label>
               How did you hear about BlackoutPoetry.com?:
                 <input type="text" name="hear" id="hear" /></label>
           </p>
           <p>
             <label>Blackout URL*:
               <input name="image" type="text" id="image" value="http://" />
             </label>
           <br /><font size="-2">*We are currently working on support of direct upload images.  In the meantime we recommend using a third-party image hosting site, like <a href="http://www.flickr.com" rel="nofollow" target="_blank">flickr.com</a> or <a href="http://www.photobucket.com" rel="nofollow" target="_blank">photobucket.com</a></font>
           </p>
           
           <p>
             <label>Blackout Description (240 Character Limit):
               <br />
               <textarea name="description" cols="60" rows="4" id="description"></textarea>
             </label>
           </p>
           <p>Prove you're not a robot: <font size="-4"><a href="javascript:MDM_openWindow('why.html','Interface1','width=270,height=330')">(Why do I have to do this??)</a></font></p>
         
           <div align="center">
             <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Lf2gwgAAAAAABngxMt5mHRC5USNnT8bjNHjDwQP"></script>
    
        <noscript>
              <iframe src="http://api.recaptcha.net/noscript?k=6Lf2gwgAAAAAABngxMt5mHRC5USNnT8bjNHjDwQP" height="300" width="500" frameborder="0"></iframe><br/>
              <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
              <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
        </noscript>         
             <br />
             <input type="submit" value="Submit" />&nbsp;&nbsp;<input type="reset" value="Clear Form" /></p>
           </div>
        </form>
    Server Side PHP Script: (sendmail.php)
    Code:
    <?php
    require_once('recaptchalib.php');
    $privatekey = "6Lf2gwgAAAAAAEOhPT7XGI4fegpxVUcXEnK8Tm9m";
    $resp = recaptcha_check_answer ($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);
    if(!$resp->is_valid) {
    header("location:captcha_error.php");
    die();}
    else if($resp->is_valid) 
    {
    $to = "mike@blackoutpoetry.com";
    $subject = "Blackout Poetry Submission";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $location_field = $_POST['location'];
    $image_field = $_POST['image'];
    $hear_field = $_POST['hear'];
    $description_field = $_POST['description'];
     
    $body = "From: $name_field\n E-Mail: $email_field\n Location: $location_field\n Heard: $hear_field\n Image: $image_field\n Description: $description_field";
     
    mail($to, $subject, $body);
     header( "Location: http://www.blackoutpoetry.com/thanks.html" );
    }
    ?>

  2. #2
    There is a bit difference from handling normal form fields and file uploads
    First, have enctype="multipart/form-data" in the HTML form
    Then on uploading, the file location will be available in $_FILES["uploaded_file"]["tmp_name"]
    You have to copy the file to a desired location.
    For more information, see this page: PHP email form with file attachment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012