fopen_variation7.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. Test fopen() function : variation: use include path create a file (relative)
  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 = create_include_path();
  17. set_include_path($newpath);
  18. runtest();
  19. $newpath = generate_next_path();
  20. set_include_path($newpath);
  21. runtest();
  22. teardown_include_path();
  23. restore_include_path();
  24. chdir("..");
  25. rmdir($thisTestDir);
  26. function runtest() {
  27. global $dir1;
  28. $tmpfile = basename(__FILE__, ".php") . ".tmp";
  29. $h = fopen($tmpfile, "w", true);
  30. fwrite($h, (binary)"This is the test file");
  31. fclose($h);
  32. $h = @fopen($tmpfile, "r");
  33. if ($h === false) {
  34. echo "Not created in working dir\n";
  35. }
  36. else {
  37. echo "created in working dir\n";
  38. fclose($h);
  39. unlink($tmpfile);
  40. }
  41. $h = @fopen($dir1.'/'.$tmpfile, "r");
  42. if ($h === false) {
  43. echo "Not created in dir1\n";
  44. }
  45. else {
  46. echo "created in dir1\n";
  47. fclose($h);
  48. unlink($dir1.'/'.$tmpfile);
  49. }
  50. }
  51. ?>
  52. ===DONE===
  53. --EXPECT--
  54. created in working dir
  55. Not created in dir1
  56. created in working dir
  57. Not created in dir1
  58. ===DONE===