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 :

$_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)
  }
}

Leave a Reply