|
-
Feb 25th, 2022, 06:54 AM
#1
Thread Starter
Fanatic Member
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.
-
Feb 25th, 2022, 07:20 AM
#2
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>
-
Feb 25th, 2022, 07:24 AM
#3
Thread Starter
Fanatic Member
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)
}
}
-
Feb 25th, 2022, 07:26 AM
#4
Re: How do I add a custom field to a POST?
 Originally Posted by tmighty2
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>
-
Feb 25th, 2022, 07:33 AM
#5
Thread Starter
Fanatic Member
Re: How do I add a custom field to a POST?
Thank you.
Code:
echo var_dump($_POST);
returns:
array(0) {
}
-
Feb 25th, 2022, 08:00 AM
#6
Thread Starter
Fanatic Member
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?
-
Feb 25th, 2022, 10:22 AM
#7
Re: How do I add a custom field to a POST?
 Originally Posted by tmighty2
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>
-
Feb 25th, 2022, 10:29 AM
#8
Thread Starter
Fanatic Member
Re: How do I add a custom field to a POST?
Thank you, but that didn't help either.
-
Feb 25th, 2022, 10:34 AM
#9
Re: How do I add a custom field to a POST?
Try var_dump($_SERVER) and/or getallheaders functions. (I'm not using PHP actively.)
cheers,
</wqw>
-
Feb 25th, 2022, 01:55 PM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|