1--TEST--
2Post a file
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9include "php_cli_server.inc";
10php_cli_server_start('var_dump($_FILES);');
11
12list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
13$port = intval($port)?:80;
14
15$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
16if (!$fp) {
17  die("connect failed");
18}
19
20$post_data = <<<POST
21-----------------------------114782935826962
22Content-Disposition: form-data; name="userfile"; filename="laruence.txt"
23Content-Type: text/plain
24
25I am not sure about this.
26
27-----------------------------114782935826962--
28
29
30POST;
31
32$post_len = strlen($post_data);
33
34if(fwrite($fp, <<<HEADER
35POST / HTTP/1.1
36Host: {$host}
37Content-Type: multipart/form-data; boundary=---------------------------114782935826962
38Content-Length: {$post_len}
39
40
41{$post_data}
42HEADER
43)) {
44	while (!feof($fp)) {
45		echo fgets($fp);
46	}
47}
48
49?>
50--EXPECTF--
51HTTP/1.1 200 OK
52Host: %s
53Connection: close
54X-Powered-By: PHP/%s
55Content-type: text/html
56
57array(1) {
58  ["userfile"]=>
59  array(5) {
60    ["name"]=>
61    string(12) "laruence.txt"
62    ["type"]=>
63    string(10) "text/plain"
64    ["tmp_name"]=>
65    string(%d) "%s"
66    ["error"]=>
67    int(0)
68    ["size"]=>
69    int(26)
70  }
71}
72