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