File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / sapi / cli / tests / php_cli_server_005.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:35 2012 UTC (12 years, 2 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, HEAD
php 5.4.3+patches

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>