xref: /PHP-7.1/sapi/cli/tests/upload_2G.phpt (revision f33c7b3e)
1--TEST--
2file upload greater than 2G
3--SKIPIF--
4<?php
5include "skipif.inc";
6
7if (PHP_INT_SIZE < 8) {
8	die("skip need PHP_INT_SIZE>=8");
9}
10
11if ($f = fopen("/proc/meminfo","r")) {
12	while (!feof($f)) {
13		if (!strncmp($line = fgets($f), "MemFree", 7)) {
14			if (substr($line,8)/1024/1024 > 3) {
15				$enough_free_ram = true;
16			}
17		}
18	}
19}
20
21if (empty($enough_free_ram)) {
22	die("skip need +3G free RAM");
23}
24
25if (getenv('TRAVIS')) {
26    die("skip Fails intermittently on travis");
27}
28?>
29--FILE--
30<?php
31
32echo "Test\n";
33
34include "php_cli_server.inc";
35
36php_cli_server_start("var_dump(\$_FILES);", false,
37	"-d post_max_size=3G -d upload_max_filesize=3G");
38
39list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
40$port = intval($port)?:80;
41$length = 2150000000;
42$output = "";
43
44$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
45if (!$fp) {
46  die("connect failed");
47}
48
49$prev = "----123
50Content-Type: text/plain; charset=UTF-8
51Content-Disposition: form-data; name=\"file1\"; filename=\"file1.txt\"\n\n";
52$post = "\n----123--\n";
53$total = $length + strlen($prev) + strlen($post);
54
55fwrite($fp, <<<EOF
56POST /index.php HTTP/1.1
57Host: {$host}
58Content-Type: multipart/form-data; boundary=--123
59Content-Length: {$total}
60
61{$prev}
62EOF
63) or die("write prev failed");
64
65$data = str_repeat("0123456789", 10000);
66for ($i = 0; $i < $length; $i += 10000 * 10) {
67	fwrite($fp, $data) or die("write failed @ ($i)");
68}
69
70fwrite($fp, $post) or die("write post failed");
71
72while (!feof($fp)) {
73	$output .= fgets($fp);
74}
75echo $output;
76fclose($fp);
77?>
78Done
79--EXPECTF--
80Test
81
82HTTP/1.1 200 OK
83Host: %s
84Date: %s
85Connection: close
86X-Powered-By: PHP/%s
87Content-type: text/html; charset=UTF-8
88
89array(1) {
90  ["file1"]=>
91  array(5) {
92    ["name"]=>
93    string(9) "file1.txt"
94    ["type"]=>
95    string(10) "text/plain"
96    ["tmp_name"]=>
97    string(%d) "%s"
98    ["error"]=>
99    int(0)
100    ["size"]=>
101    int(2150000000)
102  }
103}
104Done
105