curl_CURLOPT_READDATA.phpt 1.0 KB

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