1--TEST--
2Test fopen() function : variation: use include path create and read a file (relative)
3--CREDITS--
4Dave 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
13require_once('fopen_include_path.inc');
14
15$thisTestDir = basename(__FILE__, ".php") . ".dir";
16mkdir($thisTestDir);
17chdir($thisTestDir);
18
19$newpath = create_include_path();
20set_include_path($newpath);
21runtest();
22
23$newpath = generate_next_path();
24set_include_path($newpath);
25runtest();
26
27teardown_include_path();
28restore_include_path();
29chdir("..");
30rmdir($thisTestDir);
31
32function runtest() {
33    global $dir1;
34
35    $extraDir = "extraDir";
36
37    mkdir($dir1.'/'.$extraDir);
38    mkdir($extraDir);
39
40	$tmpfile = $extraDir . '/' . basename(__FILE__, ".php") . ".tmp";
41	$h = fopen($tmpfile, "w+", true);
42	fwrite($h, (binary) "This is the test file");
43	fclose($h);
44
45	$h = @fopen($dir1.'/'.$tmpfile, "r");
46	if ($h === false) {
47	   echo "Not created in dir1\n";
48	}
49	else {
50	   echo "created in dir1\n";
51	   fclose($h);
52	}
53
54	$h = fopen($tmpfile, "r", true);
55	if ($h === false) {
56	   echo "could not find file for reading\n";
57	}
58	else {
59	   echo "found file for reading\n";
60	   fclose($h);
61	}
62
63	unlink($tmpfile);
64        rmdir($dir1.'/'.$extraDir);
65        rmdir($extraDir);
66}
67?>
68===DONE===
69--EXPECT--
70Not created in dir1
71found file for reading
72Not created in dir1
73found file for reading
74===DONE===
75