1--TEST--
2Test copy() function: usage variations - links
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) == "WIN")
6  die("skip Invalid for Windows");
7?>
8
9--FILE--
10<?php
11/* Prototype: bool copy ( string $source, string $dest );
12   Description: Makes a copy of the file source to dest.
13     Returns TRUE on success or FALSE on failure.
14*/
15
16/* Test copy() function: Trying to create copy of links */
17
18$file_path = dirname(__FILE__);
19
20echo "*** Testing copy() with symlink and hardlink ***\n";
21$file = $file_path."/copy_variation7.tmp";
22$file_handle = fopen($file, "w");
23fwrite( $file_handle, str_repeat(b"Hello World, this is 2007 year ....\n", 100) );
24fclose($file_handle);
25
26$symlink = $file_path."/copy_variation7_symlink.tmp";
27$hardlink = $file_path."/copy_variation7_hardlink.tmp";
28
29symlink($file, $symlink);  //creating symlink
30link($file, $hardlink);  //creating hardlink
31
32echo "Size of source files => \n";
33var_dump( filesize($file_path."/copy_variation7_symlink.tmp") );  //size of the symlink itself
34clearstatcache();
35var_dump( filesize($file_path."/copy_variation7_hardlink.tmp") );  //size of the file
36clearstatcache();
37
38echo "-- Now applying copy() on source link to create copies --\n";
39echo "-- With symlink --\n";
40var_dump( copy($symlink, $file_path."/copy_copy_variation7_symlink.tmp") );
41var_dump( file_exists($file_path."/copy_copy_variation7_symlink.tmp") );
42var_dump( is_link($file_path."/copy_copy_variation7_symlink.tmp") );
43var_dump( is_file($file_path."/copy_copy_variation7_symlink.tmp") );
44var_dump( filesize($file_path."/copy_copy_variation7_symlink.tmp") );
45clearstatcache();
46
47echo "-- With hardlink --\n";
48var_dump( copy($hardlink, $file_path."/copy_copy_variation7_hardlink.tmp") );
49var_dump( file_exists($file_path."/copy_copy_variation7_hardlink.tmp") );
50var_dump( is_link($file_path."/copy_copy_variation7_hardlink.tmp") );
51var_dump( is_file($file_path."/copy_copy_variation7_hardlink.tmp") );
52var_dump( filesize($file_path."/copy_copy_variation7_hardlink.tmp") );
53clearstatcache();
54
55echo "*** Done ***\n";
56?>
57
58--CLEAN--
59<?php
60$file_path = dirname(__FILE__);
61unlink($file_path."/copy_copy_variation7_symlink.tmp");
62unlink($file_path."/copy_copy_variation7_hardlink.tmp");
63unlink($file_path."/copy_variation7_symlink.tmp");
64unlink($file_path."/copy_variation7_hardlink.tmp");
65unlink($file_path."/copy_variation7.tmp");
66?>
67
68--EXPECTF--
69*** Testing copy() with symlink and hardlink ***
70Size of source files =>
71int(%d)
72int(3600)
73-- Now applying copy() on source link to create copies --
74-- With symlink --
75bool(true)
76bool(true)
77bool(false)
78bool(true)
79int(3600)
80-- With hardlink --
81bool(true)
82bool(true)
83bool(false)
84bool(true)
85int(3600)
86*** Done ***
87