Reading data from HTTP POST method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    Reading data from HTTP POST method

    Hello,
    I'm beginner to php (actually i'm java/jsp developer),
    What i'm trying to do is Accept parameters from the HTML file and write them to a newly created file using php,
    I wrote following script but it doesn't work,

    Code:
    <?php
    
    $uploaddir = '/var/www/vhosts/nitinsawant.com/subdomains/httpdocs/files/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    
    echo '<pre>';
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "File is valid, and was successfully uploaded.\n";
    } else {
        echo "Possible file upload attack!\n";
    }
    
    echo 'Here is some more debugging info:';
    print_r($_FILES);
    
    print "</pre>";
    
    ?>
    for passing parameters to the php script I'm using following HTML file,
    post.html
    Code:
    <html> 
    <head>Post data...</head> 
    <body> 
    <form action="post.php" method="POST"> 
    ID: <input type="text" name="ID"/><br/>
    Data: <textarea cols=35 rows=15 name="data"></textarea> 
    <br/> 
    <br/> 
    <input type="submit" value="submit" /> 
    </form> 
    </body> 
    </html>
    I want to create file named "ID" at server side and append the "data" to the file.

    help me.

    regards,
    Nitin Sawant
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Check out the file system functions, namely fopen(), fwrite() and fclose().

    Also, you are not submitting files via your form so using $_FILES is pointless. You need to be using $_POST.

    Comment

    • NitinSawant
      Contributor
      • Oct 2007
      • 271

      #3
      thanks

      Thanks a lot, for posting the links.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by NitinSawant
        Thanks a lot, for posting the links.
        You're welcome.

        Mark.

        Comment

        • v08i
          New Member
          • Nov 2008
          • 2

          #5
          For file uploads to work, your html form should have enctype attribute set to multipart/form-data. Like this:

          Code:
          <form action="post.php" method="POST" enctype="multipart/form-data" >

          Comment

          • indesulsenift
            New Member
            • Dec 2010
            • 1

            #6
            your newest member

            hey. finally signed up as a member after some time of just lurking and reading posts.

            merry xmas to all!

            Comment

            Working...