Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get no file POST data with curl

with curl v8.2.1

$ curl --location 'https://my_serv' -F "flg=OK" -F "data=@test1.xml"

"test1.xml" is local file, and it is a short xml string

On the backend PHP/Apache server, I test :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$_POST[‘flg’] => OK

but

$_POST[‘data’] => empty ???

>Solution :

Files are not found in $_POST, rather check $_FILES:

An associative array of items uploaded to the current script via the HTTP POST method. The structure of this array is outlined in the POST method uploads section.


Using this index.php:

<?php

var_dump($_POST);
var_dump($_FILES);

And sending the following CURL command:

curl -X POST localhost:8082 -F foo=@/Users/somebody/Desktop/index.php -F "a=b"

Shows the following:

array(1) {
  ["a"]=>
  string(1) "b"
}
array(1) {
  ["foo"]=>
  array(6) {
    ["name"]=>
    string(9) "index.php"
    ["full_path"]=>
    string(9) "index.php"
    ["type"]=>
    string(24) "application/octet-stream"
    ["tmp_name"]=>
    string(66) "/private/var/folders/3l/bjsscl9x22g29fx7r4wc0z7r0000gn/T/phpEsSvlb"
    ["error"]=>
    int(0)
    ["size"]=>
    int(44)
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading