curl_write_file.phpt 848 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Test curl option CURLOPT_FILE
  3. --CREDITS--
  4. Mathieu Kooiman <mathieuk@gmail.com>
  5. Dutch UG, TestFest 2009, Utrecht
  6. --DESCRIPTION--
  7. Writes the value 'test' to a temporary file. Use curl to access this file and store the output in another temporary file. Tests the PHP_CURL_FILE case in curl_write().
  8. --EXTENSIONS--
  9. curl
  10. --FILE--
  11. <?php
  12. $test_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
  13. $log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
  14. $fp = fopen($log_file, 'w+');
  15. fwrite($fp, "test");
  16. fclose($fp);
  17. $testfile_fp = fopen($test_file, 'w+');
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_FILE, $testfile_fp);
  20. curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
  21. curl_exec($ch);
  22. curl_close($ch);
  23. fclose($testfile_fp);
  24. echo file_get_contents($test_file);
  25. // cleanup
  26. unlink($test_file);
  27. unlink($log_file);
  28. ?>
  29. --EXPECT--
  30. test