Script that saves form data to a text file and uploads a picture?

Discussion in 'PHP' started by ivelin_91, Sep 18, 2010.

  1. #1
    Hello,

    I need a php script that makes it possible for a visitor to enter those optional details:
    His/her name
    email address
    telephone
    further details
    two radio buttons - face and back

    and saves it to a text file (data.txt for example).
    The same script should also have an image uploader and the submit button should both upload the pic to the server and save the form details to the text file(and the text file should not be overwritten).
     
    ivelin_91, Sep 18, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Refer to the link in my signature (surrounded by asterisks)
     
    danx10, Sep 18, 2010 IP
  3. ivelin_91

    ivelin_91 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, I definitely would've reffered to the link, had it not been an useless advertisement.
     
    ivelin_91, Sep 18, 2010 IP
  4. seoforall

    seoforall Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $fh = fopen("datadump.txt", "a")

    foreach ($_POST as $key=>$value) {
    $thisline = "$key = $value\n";
    fwrite($fh, $thisline);
    }

    fwrite($fh, "\n******* END OF RECORD ********\n\n");
    fclose($fh);


    Thats for saving your data to a .txt file

    as per saving the uploaded files you'll have to mess with file upload functions and $_FILE array (to get the name, tempname, etc).
    here's a good article for you to follow step by step for the file upload part : http://php.about.com/od/advancedphp/ss/php_file_upload.htm

    know that when you upload a file, php saves it to a temp location and under a temp name. You will have to then move the temp file to a desired location (using moveuploadedfile() ) and rename it to a desired name (you may also get the original file's name and rename the temp file to it).

    anyways, you'll find a step by step guide in the URL i posted for the file upload part

    also, the code above is not tested .. i just wrote it here .. i sometimes make typos, so watch out :)

    and also, the file upload part and the saving of your data dump is a dependent of your server's configuration (it should allow the PHP to create and/or modify files).

    good luck
     
    seoforall, Sep 18, 2010 IP