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