1--TEST--
2Test CURLOPT_READDATA without a callback function
3--CREDITS--
4Mattijs 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
18ob_start();
19
20$ch = curl_init($url);
21curl_setopt($ch, CURLOPT_URL, $url);
22curl_setopt($ch, CURLOPT_POST, true);
23curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
24curl_setopt($ch, CURLOPT_READDATA, fopen($tempname, 'rb'));
25curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', "Content-Length: {$datalen}"));
26
27if (false === $response = curl_exec($ch)) {
28    echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch);
29} else {
30    echo $response;
31}
32
33curl_close($ch);
34
35// Clean the temporary file
36@unlink($tempname);
37
38--EXPECT--
39array(2) {
40  ["hello"]=>
41  string(5) "world"
42  ["smurf"]=>
43  string(4) "blue"
44}
45