fopen_variation9.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. Test fopen() function : variation: use include path and stream context create a file, relative path
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
  8. * Description: Open a file or a URL and return a file pointer
  9. * Source code: ext/standard/file.c
  10. * Alias to functions:
  11. */
  12. require_once('fopen_include_path.inc');
  13. $thisTestDir = basename(__FILE__, ".php") . ".dir";
  14. mkdir($thisTestDir);
  15. chdir($thisTestDir);
  16. $newpath = relative_include_path();
  17. set_include_path($newpath);
  18. runtest();
  19. $newpath = generate_next_rel_path();
  20. set_include_path($newpath);
  21. runtest();
  22. teardown_relative_path();
  23. restore_include_path();
  24. chdir("..");
  25. rmdir($thisTestDir);
  26. function runtest() {
  27. $tmpfile = basename(__FILE__, ".php") . ".tmp";
  28. $h = fopen($tmpfile, "w", true);
  29. fwrite($h, (binary) "This is the test file");
  30. fclose($h);
  31. $h = @fopen($tmpfile, "r");
  32. if ($h === false) {
  33. echo "Not created in working dir\n";
  34. }
  35. else {
  36. echo "created in working dir\n";
  37. fclose($h);
  38. unlink($tmpfile);
  39. }
  40. $h = @fopen('dir1/'.$tmpfile, "r");
  41. if ($h === false) {
  42. echo "Not created in dir1\n";
  43. }
  44. else {
  45. echo "created in dir1\n";
  46. fclose($h);
  47. unlink('dir1/'.$tmpfile);
  48. }
  49. }
  50. ?>
  51. ===DONE===
  52. --EXPECT--
  53. created in working dir
  54. Not created in dir1
  55. created in working dir
  56. Not created in dir1
  57. ===DONE===