bug48207.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test curl_setopt() CURLOPT_FILE readonly file handle
  3. --CREDITS--
  4. Mark van der Velden
  5. #testfest Utrecht 2009
  6. --EXTENSIONS--
  7. curl
  8. --FILE--
  9. <?php
  10. /*
  11. * Description : Adds a file which stores the received data from curl_exec();
  12. * Source code : ext/curl/multi.c
  13. * Test documentation: http://wiki.php.net/qa/temp/ext/curl
  14. */
  15. // Figure out what handler to use
  16. include 'server.inc';
  17. $host = curl_cli_server_start();
  18. if(!empty($host)) {
  19. // Use the set Environment variable
  20. $url = "$host/get.inc?test=1";
  21. } else {
  22. // Create a temporary file for the test
  23. $tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
  24. $url = 'file://'. $tempname;
  25. // add the test data to the file
  26. file_put_contents($tempname, "Hello World!\nHello World!");
  27. }
  28. $tempfile = tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
  29. $fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
  30. $ch = curl_init($url);
  31. try {
  32. curl_setopt($ch, CURLOPT_FILE, $fp);
  33. } catch (ValueError $exception) {
  34. echo $exception->getMessage() . "\n";
  35. }
  36. curl_exec($ch);
  37. curl_close($ch);
  38. is_file($tempfile) and @unlink($tempfile);
  39. isset($tempname) and is_file($tempname) and @unlink($tempname);
  40. ?>
  41. --EXPECT--
  42. curl_setopt(): The provided file handle must be writable
  43. Hello World!
  44. Hello World!