0

I have problem with curl file upload using PHP when form name of input file is an integer: <input type="file" name="1">

I have following array that I put in CURLOPT_POSTFIELDS to get multipart/form-data:

$array = array(
    "MAX_FILE_SIZE" => 80000,
    "1" => '@'.$cfg['lpath'].'logos/'.domain($projekt['adres']).'.jpg;type=image/jpeg',
    "2" => '@'.($cfg['lpath']==''?'/dev/null':'NUL:').';filename=',
    "3" => '@'.($cfg['lpath']==''?'/dev/null':'NUL:').';filename=',
    "send" => 'send it'
);

I send it to server and var_dump($_POST, $_FILES) is as follow:

$_POST:

array(2) {
  ["MAX_FILE_SIZE"]=>
  string(5) "80000"
  ["send"]=>
  string(7) "send it"
}

$_FILES:

array(1) {
  ["MAX_FILE_SIZE"]=>
  array(5) {
    ["name"]=>
    string(0) ""
    ["type"]=>
    string(0) ""
    ["tmp_name"]=>
    string(0) ""
   ["error"]=>
    int(4)
    ["size"]=>
    int(0)
  }
}

When I change array keys to letters it works as expected:

$_FILES:

array(3) {
  ["a"]=>
  array(5) {
    ["name"]=>
    string(16) "filename.jpg"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/phpRZMiRA"
    ["error"]=>
    int(0)
    ["size"]=>
    int(6567)
  }
  ["b"]=>
  array(5) {
    ["name"]=>
    string(0) ""
    ["type"]=>
    string(0) ""
    ["tmp_name"]=>
    string(0) ""
    ["error"]=>
    int(4)
    ["size"]=>
    int(0)
  }
  ["c"]=>
  array(5) {
    ["name"]=>
    string(0) ""
    ["type"]=>
    string(0) ""
    ["tmp_name"]=>
    string(0) ""
    ["error"]=>
    int(4)
    ["size"]=>
    int(0)
  }
}

Is it a bug? Is it possible to send such an array using curl?

My PHP Version is 5.3.25 Curl version 7.30.0

1 Answer 1

0

Name tokens in HTML have to follow a certain restriction.

6.2 SGML basic types

...

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Source: http://www.w3.org/TR/html4/types.html#type-cdata

One solution could be to prefix your inputs with say "data-"<number> and your post would work as expected.

There are plenty of questions on StackOverflow that address this issue. Here is one: valid value for name attribute in html

Sign up to request clarification or add additional context in comments.

2 Comments

I don't have access to this HTML form and I need to send data via curl. Maybe using php cocket would do the trick.
Would it be possible to try and contact the author/responsible and ask for a rather simple change? Working off plain wrong convention is a hack at best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.