1--TEST--
2Test copy() function: usage variations - copy empty file across dirs
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip Only run on 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 source file
16     into different destination dir paths given in various notations */
17
18echo "*** Test copy() function: copying file across directories ***\n";
19$base_dir = dirname(__FILE__)."/copy_variation6";
20mkdir($base_dir);
21
22$sub_dir = $base_dir."/copy_variation6_sub";
23mkdir($sub_dir);
24
25$dirname_with_blank = $sub_dir."/copy variation6";
26mkdir($dirname_with_blank);
27
28$src_file_name = dirname(__FILE__)."/copy_variation6.tmp";
29fclose( fopen($src_file_name, "w") );
30
31echo "Size of source file => ";
32var_dump( filesize($src_file_name) );
33clearstatcache();
34
35$dests = array(
36  $base_dir."/copy_copy_variation6.tmp",
37  $base_dir."/copy_variation6_sub/copy_copy_variation6.tmp",
38  "$sub_dir/copy_copy_variation6.tmp",
39  "$sub_dir/../copy_copy_variation6.tmp",
40  "$sub_dir/../copy_variation6_sub/copy_copy_variation6.tmp",
41  "$sub_dir/..///../copy_copy_variation6.tmp",
42  "$sub_dir/..///../*",
43  "$dirname_with_blank/copy_copy_variation6.tmp"
44);
45
46echo "\n-- Now applying copy() on source file to create copies --";
47$count = 1;
48foreach($dests as $dest) {
49  echo "\n-- Iteration $count --\n";
50
51  echo "Copy operation => ";
52  var_dump( copy($src_file_name, $dest) );
53
54  echo "Existence of destination file => ";
55  var_dump( file_exists($dest) );
56
57   if( file_exists($dest) ) {
58    echo "Destination file name is => ";
59    print($dest);
60    echo "\n";
61
62    echo "Size of source file => ";
63    var_dump( filesize($src_file_name) );
64    clearstatcache();
65
66    echo "Size of destination file => ";
67    var_dump( filesize($dest) );
68    clearstatcache();
69
70    unlink("$dest");
71  }
72
73  $count++;
74}
75
76unlink($src_file_name);
77rmdir($dirname_with_blank);
78rmdir($sub_dir);
79rmdir($base_dir);
80
81echo "*** Done ***\n";
82?>
83
84--EXPECTF--
85*** Test copy() function: copying file across directories ***
86Size of source file => int(0)
87
88-- Now applying copy() on source file to create copies --
89-- Iteration 1 --
90Copy operation => bool(true)
91Existence of destination file => bool(true)
92Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp
93Size of source file => int(0)
94Size of destination file => int(0)
95
96-- Iteration 2 --
97Copy operation => bool(true)
98Existence of destination file => bool(true)
99Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
100Size of source file => int(0)
101Size of destination file => int(0)
102
103-- Iteration 3 --
104Copy operation => bool(true)
105Existence of destination file => bool(true)
106Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
107Size of source file => int(0)
108Size of destination file => int(0)
109
110-- Iteration 4 --
111Copy operation => bool(true)
112Existence of destination file => bool(true)
113Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp
114Size of source file => int(0)
115Size of destination file => int(0)
116
117-- Iteration 5 --
118Copy operation => bool(true)
119Existence of destination file => bool(true)
120Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp
121Size of source file => int(0)
122Size of destination file => int(0)
123
124-- Iteration 6 --
125Copy operation => bool(true)
126Existence of destination file => bool(true)
127Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp
128Size of source file => int(0)
129Size of destination file => int(0)
130
131-- Iteration 7 --
132Copy operation =>
133Warning: copy(%s/copy_variation6/copy_variation6_sub/..///../*): failed to open stream: No such file or directory in %s on line %d
134bool(false)
135Existence of destination file => bool(false)
136
137-- Iteration 8 --
138Copy operation => bool(true)
139Existence of destination file => bool(true)
140Destination file name is => %s/copy_variation6/copy_variation6_sub/copy variation6/copy_copy_variation6.tmp
141Size of source file => int(0)
142Size of destination file => int(0)
143*** Done ***
144