Results 1 to 10 of 10

Thread: How do I add a custom field to a POST?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Question How do I add a custom field to a POST?

    I am uploading a file to my server using VB6 and Winsock.

    Code:
    POST /upload.php? HTTP/1.0
    Host: somedomain.com
    Content-Type: multipart/form-data, boundary=uzTxw5X5HVmtcWrFhatyjH2QGVcMlBj2
    Content-Length: 127289
    --uzTxw5X5HVmtcWrFhatyjH2QGVcMlBj2
    Content-Disposition: form-data; name="file"; filename="C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca"; realpath="C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca"
    Content-Type: application/octet-stream
    --uzTxw5X5HVmtcWrFhatyjH2QGVcMlBj2--
    The upload works fine.

    On the server, I would like to know the file's path on the client pc (=> "C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca").
    That is why I have tried to add a custom field named "realpath" (realpath="C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca")

    I have tried to get this field in my php script, but it's empty.

    Code:
    <?php
        move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
    
        $path = "uploads/";
        $name = $_FILES["file"]["name"];
        
        $fullpath1 = $_FILES["file"]["realpath"];
        $fullpath2 = $_POST["realpath"];
    
        echo "fullpath: . $fullpath1";
        echo "fullpath: . $fullpath2";
    ?>
    How could I pass a custom field with my POST?

    Thank you!

    ps: I don't have access to php 8.1 yet, so I can't use "full_path".
    Last edited by tmighty2; Feb 25th, 2022 at 07:00 AM.

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: How do I add a custom field to a POST?

    Try var_dump($_POST) and var_dump($_FILES)

    Note that $_FILES structure is fixed (outlined in POST method uploads) so you cannot add any custom "realpath" attribute like this.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: How do I add a custom field to a POST?

    Thank you, but it does not reveal any more info:

    Code:
    array(0) {
    }
    array(1) {
      ["file"]=>
      array(5) {
        ["name"]=>
        string(13) "dtctlsu.oca"
        ["type"]=>
        string(0) ""
        ["tmp_name"]=>
        string(14) "/tmp/php8Q3TVc"
        ["error"]=>
        int(0)
        ["size"]=>
        int(149)
      }
    }

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: How do I add a custom field to a POST?

    Quote Originally Posted by tmighty2 View Post
    Thank you, but it does not reveal any more info:
    I already told you it's not possible to extend $_FILES with custom attributes.

    Try using a "normal" custom header instead so it can be dumped in $_POST like this:

    Code:
    Content-Disposition: form-data; name="file"; filename="C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca"
    Content-Type: application/octet-stream
    X-Real-Path: C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca
    cheers,
    </wqw>

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: How do I add a custom field to a POST?

    Thank you.


    Code:
    echo var_dump($_POST);
    
    returns:
    
    array(0) {
    }

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: How do I add a custom field to a POST?

    Do you have any idea why echo var_dump($_POST); does not return the X-Real-Path?

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: How do I add a custom field to a POST?

    Quote Originally Posted by tmighty2 View Post
    Do you have any idea why echo var_dump($_POST); does not return the X-Real-Path?
    Probably a limitation of PHP multi-part request handling.

    You can try moving it to main request header at the top (before first multi-part boundary).

    cheers,
    </wqw>

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: How do I add a custom field to a POST?

    Thank you, but that didn't help either.

  9. #9

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: How do I add a custom field to a POST?

    According to an answer on stackexchange, I have now tried the following:

    Code:
    POST /upload.php? HTTP/1.0
    Host: myserver.com
    Content-Type: multipart/form-data, boundary=004UCzhgJdCM8iqrgTkk0m7UVmLdOk03
    Content-Length: 423
    --004UCzhgJdCM8iqrgTkk0m7UVmLdOk03
    Content-Disposition: form-data; name="param1"
    Content-Type: text/plain
    C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca
    --004UCzhgJdCM8iqrgTkk0m7UVmLdOk03--
    Content-Disposition: multipart/form-data; name="file"; filename="C:/Program Files (x86)/Microsoft Visual Studio/VB98/dtctlsu.oca"
    Content-Type: application/octet-stream
    --004UCzhgJdCM8iqrgTkk0m7UVmLdOk03--

    Thank you!
    Last edited by tmighty2; Feb 25th, 2022 at 05:20 PM.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width