xref: /PHP-8.4/sapi/cli/tests/upload_2G.phpt (revision 13f04116)
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 (disk_free_space(sys_get_temp_dir()) < 2300000000) {
12    die("skip need more than 2.15G of free disk space for the uploaded file");
13}
14
15if (!file_exists('/proc/meminfo')) {
16    die('skip Cannot check free RAM from /proc/meminfo on this platform');
17}
18
19$free_ram = 0;
20if ($f = fopen("/proc/meminfo","r")) {
21    while (!feof($f)) {
22        if (preg_match('/MemFree[^\d]*(\d+)/i', fgets($f), $m)) {
23            $free_ram = max($free_ram, $m[1]/1024/1024);
24            if ($free_ram > 3) {
25                $enough_free_ram = true;
26            }
27        }
28    }
29}
30
31if (empty($enough_free_ram)) {
32    die(sprintf("skip need +3G free RAM, but only %01.2f available", $free_ram));
33}
34
35if (getenv('CIRRUS_CI')) die('skip Fails on Cirrus');
36
37if (getenv('SKIP_PERF_SENSITIVE')) {
38    die("skip Test may be very slow if PHP is instrumented");
39}
40?>
41--CONFLICTS--
42all
43--FILE--
44<?php
45
46echo "Test\n";
47
48include "php_cli_server.inc";
49
50php_cli_server_start("var_dump(\$_FILES);", null,
51    ["-d", "post_max_size=3G", "-d", "upload_max_filesize=3G"]);
52
53$length = 2150000000;
54$output = "";
55
56$host = PHP_CLI_SERVER_HOSTNAME;
57$fp = php_cli_server_connect();
58
59$prev = "----123
60Content-Type: text/plain; charset=UTF-8
61Content-Disposition: form-data; name=\"file1\"; filename=\"file1.txt\"\n\n";
62$post = "\n----123--\n";
63$total = $length + strlen($prev) + strlen($post);
64
65fwrite($fp, <<<EOF
66POST /index.php HTTP/1.1
67Host: {$host}
68Content-Type: multipart/form-data; boundary=--123
69Content-Length: {$total}
70
71{$prev}
72EOF
73) or die("write prev failed");
74
75$data = str_repeat("0123456789", 10000);
76for ($i = 0; $i < $length; $i += 10000 * 10) {
77    fwrite($fp, $data) or die("write failed @ ($i)");
78}
79
80fwrite($fp, $post) or die("write post failed");
81
82while (!feof($fp)) {
83    $output .= fgets($fp);
84}
85echo $output;
86fclose($fp);
87?>
88Done
89--EXPECTF--
90Test
91HTTP/1.1 200 OK
92Host: %s
93Date: %s
94Connection: close
95X-Powered-By: PHP/%s
96Content-type: text/html; charset=UTF-8
97
98array(1) {
99  ["file1"]=>
100  array(6) {
101    ["name"]=>
102    string(9) "file1.txt"
103    ["full_path"]=>
104    string(9) "file1.txt"
105    ["type"]=>
106    string(10) "text/plain"
107    ["tmp_name"]=>
108    string(%d) "%s"
109    ["error"]=>
110    int(0)
111    ["size"]=>
112    int(2150000000)
113  }
114}
115Done
116