1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link with same name in diff. dir
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip no symlinks on Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype: bool symlink ( string $target, string $link );
12   Description: creates a symbolic link to the existing target with the specified name link
13
14   Prototype: bool is_link ( string $filename );
15   Description: Tells whether the given file is a symbolic link.
16
17   Prototype: bool link ( string $target, string $link );
18   Description: Create a hard link
19
20   Prototype: int linkinfo ( string $path );
21   Description: Gets information about a link
22*/
23
24/* Variation 8 : Create soft/hard link to different directory */
25
26/* creating link to a file in different dir with the same name as the file */
27echo "\n*** Create hard link in different directory with same filename ***\n";
28// temp file used
29$file_path = dirname(__FILE__);
30$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
31// temp link name used
32$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
33mkdir($dirname);
34$linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
35// create temp file
36$fp = fopen($filename, "w");
37fclose($fp);
38
39var_dump( link($filename, $dirname."/") ); // this fails indicating file exists
40// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
41var_dump( link($filename, $dirname."/".$linkname) );  // this works fine
42// delete link
43unlink($dirname."/".$linkname);
44// delete temp file
45unlink($filename);
46// delete temp dir
47rmdir($dirname);
48
49echo "\n*** Create soft link in different directory with same filename ***\n";
50$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
51// temp link name used
52$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
53mkdir($dirname);
54$linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
55// create temp file
56$fp = fopen($filename, "w");
57fclose($fp);
58
59var_dump( symlink($filename, $dirname."/") ); // this fails indicating file exists
60// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
61var_dump( symlink($filename, $dirname."/".$linkname) );  // this works fine
62// delete link
63unlink($dirname."/".$linkname);
64// delete temp file
65unlink($filename);
66// delete temp dir
67rmdir($dirname);
68
69echo "Done\n";
70?>
71--EXPECTF--
72*** Create hard link in different directory with same filename ***
73
74Warning: link(): File exists in %s on line %d
75bool(false)
76bool(true)
77
78*** Create soft link in different directory with same filename ***
79
80Warning: symlink(): File exists in %s on line %d
81bool(false)
82bool(true)
83Done
84