2 /* Prototype: bool symlink ( string $target, string $link );
3 Description: creates a symbolic link to the existing target with the specified name link
5 Prototype: bool is_link ( string $filename );
6 Description: Tells whether the given file is a symbolic link.
8 Prototype: bool link ( string $target, string $link );
9 Description: Create a hard link
11 Prototype: int linkinfo ( string $path );
12 Description: Gets information about a link
15 /* Variation 3 : Create file and a soft link to the file
16 Access data of the file through the soft link
17 Update the file through soft link
18 Check size of file and soft link link
21 $file_path = dirname(__FILE__
);
22 echo "*** Accessing and updating data of file through soft link ***\n";
23 // Creating file and inserting data into it
24 $filename = "$file_path/symlink_link_linkinfo_is_link_variation3.tmp";
27 $file = fopen($filename, "w");
29 // create soft link to file
30 $linkname = "$file_path/symlink_link_linkinfo_is_link_link_variation3.tmp";
31 var_dump( symlink($filename, $linkname) );
32 // storing size of symlink in a local variable
33 $link_stat = lstat($linkname); // lstat of link
34 $link_size = $link_stat[7]; // size of soft link
36 // fill data into file
37 fwrite($file, str_repeat("text", 20) );
40 echo "\n-- Access data of the file through the soft link --\n";
41 $data_from_link = file_get_contents($linkname); // data read from $filename
42 var_dump( $data_from_link );
44 echo "\n-- Check size of soft link and file --\n";
45 var_dump( filesize($filename) );
46 var_dump( filesize($linkname) );
48 // taking lstat of symlink
49 $stat = lstat($linkname);
50 // checking that size of symlink remains same
51 if ($link_size == $stat[7])
52 echo "\nSoft link size remains same \n";
54 echo "\nWarning: Soft link size has changed \n";
56 echo "\n-- Updating file with data through soft link --\n";
57 // append link with data
58 $fp = fopen($linkname, "a"); // open in append mode
59 fwrite($fp, "Hello World");
62 // now check temp file for data; it should append "Hello World"
63 $data_from_file = file_get_contents($filename);
64 var_dump( $data_from_file );
66 echo "\n-- Check size of soft link and file --\n";
67 var_dump( filesize($filename) );
68 var_dump( filesize($linkname) );
70 // taking lstat of symlink
71 $stat = lstat($linkname);
72 // checking that size of symlink remains same
73 if ($link_size == $stat[7])
74 echo "\nSoft link size remains same \n";
76 echo "\nWarning: Soft link size has changed \n";
78 echo "\n-- Updating file with data and check data through soft link --\n";
80 $file = fopen($filename, "w");
81 fwrite($file, "Hello World");
84 // now check link for data; it should echo "Hello World"
85 $data_from_link = file_get_contents($linkname);
86 var_dump( $data_from_link );
88 echo "\n-- Check size of soft link and file --\n";
89 var_dump( filesize($filename) );
90 var_dump( filesize($linkname) );
92 // taking lstat of symlink
93 $stat = lstat($linkname);
94 // checking that size of symlink remains same
95 if ($link_size == $stat[7])
96 echo "\nSoft link size remains same \n";
98 echo "\nWarning: Soft link size has changed \n";
102 // delete the temporary file