fopen_variation17.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Test fopen() function : variation: use include path create and read 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. $extraDir = "extraDir17";
  29. mkdir($dir1.'/'.$extraDir);
  30. mkdir($extraDir);
  31. $tmpfile = $extraDir . '/' . basename(__FILE__, ".php") . ".tmp";
  32. $h = fopen($tmpfile, "w+", true);
  33. fwrite($h, (binary) "This is the test file");
  34. fclose($h);
  35. $h = @fopen($dir1.'/'.$tmpfile, "r");
  36. if ($h === false) {
  37. echo "Not created in dir1\n";
  38. }
  39. else {
  40. echo "created in dir1\n";
  41. fclose($h);
  42. }
  43. $h = fopen($tmpfile, "r", true);
  44. if ($h === false) {
  45. echo "could not find file for reading\n";
  46. }
  47. else {
  48. echo "found file for reading\n";
  49. fclose($h);
  50. }
  51. unlink($tmpfile);
  52. rmdir($dir1.'/'.$extraDir);
  53. rmdir($extraDir);
  54. }
  55. ?>
  56. ===DONE===
  57. --EXPECT--
  58. Not created in dir1
  59. found file for reading
  60. Not created in dir1
  61. found file for reading
  62. ===DONE===