Results 1 to 3 of 3

Thread: Upload Form

  1. #1
    Join Date
    Sep 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Upload Form

    Hi everyone!

    I need to have a web page that allows visitors to email me their favorite photo and I am using basic html and PHP. However, I am doing something wrong, because I receive the visitor's information but not the image.

    PLEASE HELP!

    Here is the page's html:

    <form method="post" action="photos.php" enctype="multipart/form-data">


    <table cellspacing=0 cellpadding=5 width="95%" border=1 bordercolor="#3399FF">
    <tbody>
    <tr>


    <td width="40%" class="blackp"><strong>Name of mum-to-be:</strong>&nbsp;</td>
    <td width="60%"><div align="left" class="blackp">
    <input type="text" maxlength=35 size=45 name="name" />
    </div></td>
    </tr>
    <tr>

    <td class="blackp" width="40%"><strong>Email address:</strong>&nbsp;</td>
    <td width="60%"><div align="left" class="blackp">
    <input type="text" maxlength=35 size=45 name="email" />
    </div></td>
    </tr>
    <tr>

    <td class="blackp" width="40%"><strong>Phone number:</strong>&nbsp;</td>
    <td width="60%"><div align="left" class="blackp">
    <input type="text" maxlength=15 size=45 name="phone" />
    </div></td>
    </tr>
    <tr>

    <td class="blackp" width="40%"><input type="hidden" name="max_file_size" value="1000000" />
    <strong>Photo to be uploaded:</strong>&nbsp;</td>
    <td width="60%"><div align="left" class="blackp">
    <input type="file" name="uploadfile" size="45" />

    </div></td>
    </tr>
    <tr>

    <td class="blackp" width="40%"><strong>Photo captions:</strong>&nbsp;</td>
    <td width="60%"><div align="left" class="blackp">
    <input type="text" maxlength=70 size=45 name="captions" />
    </div></td>
    </tr>
    <tr>
    <td width="40%" height=19 class="blackp">Click button to <strong>send
    your email</strong>.</td>
    <td width="60%" class="blackp"><input name="contactus" type = "submit" class="blackp" value="send" /></td>
    </tr>
    </tbody>
    </table>

    </form>


    And here is the PHP coding:

    <?



    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $phone = $_REQUEST['phone'] ;
    $uploadfile = $_REQUEST['uploadfile'] ;
    $explanation = $_REQUEST['explanation'] ;
    $captions = $_REQUEST['captions'] ;

    if (!isset($_REQUEST['email'])) {
    header( "Location: http://www.britishbabyshower.co.uk/photos.html" );
    }


    elseif (empty($name) || empty($email)) {
    header( "Location: http://www.britishbabyshower.co.uk/error.html" );
    }


    else {
    mail( "babiesonthego@yahoo.com", "Contact Us Form",
    "Name: $name\nPhone Number: $phone\nEmail Address: $email\nImage Uploaded: $uploadfile\nCaptions: $captions",
    "From: $name <$email>" );

    header( "Location: http://www.britishbabyshower.co.uk/thankyou.html" );
    }

    ?>

  2. #2
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i think...
    $uploadfile = $_REQUEST['uploadfile'] ;
    should really be $uploadfile = $_FILE['uploadfile'] ;

    i'm not sure tho.
    also i dont think i've ever used request to get info from a form before..usually $_POST or $_GET...but i guess $_REQUEST works too, so tats nice to know


    i have no clue about sending files through email using php tho so i'm not sure if you will have to modify the email sending part of the code

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $_FILE array was only included in $_REQUEST through version 4.3, or earlier.
    $_REQUEST is only POST/GET/COOKIE.

    Using REQUEST is also vague because you don't know where it's coming from. I'd recommend against that.

    For sending an attachment, you need to alter the headers of the email. It's the fourth parameter:
    mail($to,$subject,$bodytext,$headers);

    Headers are used like this:
    $headers = "From: me@my.com,\r\nReply-to: me@my.com";

    It's more complex sending a file, though, so I suggest you do some research there.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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