Thread: file upload form in c++

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    file upload form in c++

    Okay
    I know that to duplicate
    Code:
    <form action="./test.php" method="post">
    <input type="hidden" name="field" value="myval">
    <input type="submit" name="subby" value="didsubmit">
    </form>
    you send the command
    Code:
    POST /test.php field=myval&subby=didsubmit HTTP/1.1
    But I don't know how to mimic file upload forms like
    Code:
    <form action="./test.php" method="post">
    <input type="file" name="myupload">
    <input type="submit">
    </form>
    How do I do this?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You send this command? That's not correct HTTP, actually. If you do
    Code:
    POST /test.php?field=myval&subby=didsubmit HTTP/1.1
    then you have at least a syntactically correct request-line, but it's still not a valid HTTP/1.1 request. Also, the parameters are encoded as GET parameters, not POST parameters, which can and will confuse scripts that make the distinction.
    Code:
    POST /test.php?field=myval&subby=didsubmit HTTP/1.1
    Host: www.example.com
    This is the very least you have to send for it to be valid HTTP/1.1. This doesn't solve the GET vs PUT variable problem, though. For that, you have to move the parameters to the entity body.
    Code:
    POST /test.php HTTP/1.1
    Host: www.example.com
    Content-type: application/x-www-form-urlencoded
    Content-length: 27
    
    field=myval&subby=didsubmit
    Now, file upload is even more complicated. It starts with your form suffering from incompatibility problems. I don't know if any browsers actually submit data in such a form. I know for sure that the file upload won't work with PHP. If you want a file upload, then you have to give the form the enctype="multipart/form-data". Otherwise, you'll have problems.

    Now, I'm not going to type up how to encode such a request. You can find an example in the HTML 4.01 spec. Another valuable resource is the HTTP/1.1 spec.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Please help me with parsing numbers form a file
    By jmmjm in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2007, 03:06 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM