Annotation of embedaddon/php/ext/curl/tests/curl_CURLOPT_READDATA.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test CURLOPT_READDATA without a callback function
                      3: --CREDITS--
                      4: Mattijs Hoitink mattijshoitink@gmail.com
                      5: #Testfest Utrecht 2009
                      6: --SKIPIF--
                      7: <?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?>
                      8: --FILE--
                      9: <?php
                     10: 
                     11: // The URL to POST to
                     12: $url = getenv('PHP_CURL_HTTP_REMOTE_SERVER') . '/get.php?test=post';
                     13: 
                     14: // Create a temporary file to read the data from
                     15: $tempname = tempnam(sys_get_temp_dir(), 'CURL_DATA');
                     16: $datalen = file_put_contents($tempname, "hello=world&smurf=blue");
                     17: 
                     18: ob_start();
                     19: 
                     20: $ch = curl_init($url);
                     21: curl_setopt($ch, CURLOPT_URL, $url);
                     22: curl_setopt($ch, CURLOPT_POST, true);
                     23: curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                     24: curl_setopt($ch, CURLOPT_READDATA, fopen($tempname, 'rb'));
                     25: curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', "Content-Length: {$datalen}"));
                     26: 
                     27: if (false === $response = curl_exec($ch)) {
                     28:     echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch);
                     29: } else {
                     30:     echo $response;
                     31: }
                     32: 
                     33: curl_close($ch);
                     34: 
                     35: // Clean the temporary file
                     36: @unlink($tempname);
                     37: 
                     38: --EXPECT--
                     39: array(2) {
                     40:   ["hello"]=>
                     41:   string(5) "world"
                     42:   ["smurf"]=>
                     43:   string(4) "blue"
                     44: }

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