Need PHP Contact Form with file upload

Discussion in 'PHP' started by krishnapmk, Oct 31, 2010.

  1. #1
    Hi, i need a PHP sample script for contact form with fileupload. please help me.

    Thanks
     
    krishnapmk, Oct 31, 2010 IP
  2. max2010

    max2010 Greenhorn

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    you should first setup an html form like this:

    <form enctype="multipart/form-data" action="myphpscript.php" method="post" name="form">
    ...
    ... here put your other input fields
    ...
    ...
    <label>Submit your file</label>
    <input type="file" name="myfile" />
    <input type="submit" name="submit" value="Submit" />
    </form>


    then, in your myphpscript.php you can find the uploaded file parameters in the array $_FILES['myfile']

    the saved file is in a temp dir, so you need to save the uploaded file into a new file, doing like this:

    $myfilename="images/myfilename.jpg"; // setup your filename with folder if needed

    $move_result = move_uploaded_file($_FILES['myfile']['tmp_name'], $myfilename);

    if ($move_result) {
    echo 'success';
    // put your script in case of success...
    }

    else {
    echo 'error';
    // put your script in case of fail...
    }
     
    max2010, Nov 1, 2010 IP
  3. krishnapmk

    krishnapmk Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you Max
     
    krishnapmk, Nov 1, 2010 IP