upload_2G.phpt 2.3 KB

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