Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


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)
    <form method="post" action="sendmail.php" name="msgform">
               <input type="text" name="name" id="name" />
               <input type="text" name="email" id="email" />
             <label>Where ya from?:
               <input type="text" name="location" id="location" />
               How did you hear about BlackoutPoetry.com?:
                 <input type="text" name="hear" id="hear" /></label>
             <label>Blackout URL*:
               <input name="image" type="text" id="image" value="http://" />
           <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>
             <label>Blackout Description (240 Character Limit):
               <br />
               <textarea name="description" cols="60" rows="4" id="description"></textarea>
           <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>
              <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"/>
             <br />
             <input type="submit" value="Submit" />&nbsp;&nbsp;<input type="reset" value="Clear Form" /></p>
    Server Side PHP Script: (sendmail.php)
    $privatekey = "6Lf2gwgAAAAAAEOhPT7XGI4fegpxVUcXEnK8Tm9m";
    $resp = recaptcha_check_answer ($privatekey,
    if(!$resp->is_valid) {
    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


Copyright 1999 - 2012