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 Do not 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 = __DIR__."/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 = __DIR__."/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  echo "Destination file name is => ";
58  print($dest);
59  echo "\n";
60
61  echo "Size of source file => ";
62  var_dump( filesize($src_file_name) );
63  clearstatcache();
64
65  echo "Size of destination file => ";
66  var_dump( filesize($dest) );
67  clearstatcache();
68
69  unlink("$dest");
70
71  $count++;
72}
73
74unlink($src_file_name);
75rmdir($dirname_with_blank);
76rmdir($sub_dir);
77rmdir($base_dir);
78
79echo "*** Done ***\n";
80?>
81--EXPECTF--
82*** Test copy() function: copying file across directories ***
83Size of source file => int(0)
84
85-- Now applying copy() on source file to create copies --
86-- Iteration 1 --
87Copy operation => bool(true)
88Existence of destination file => bool(true)
89Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp
90Size of source file => int(0)
91Size of destination file => int(0)
92
93-- Iteration 2 --
94Copy operation => bool(true)
95Existence of destination file => bool(true)
96Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
97Size of source file => int(0)
98Size of destination file => int(0)
99
100-- Iteration 3 --
101Copy operation => bool(true)
102Existence of destination file => bool(true)
103Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
104Size of source file => int(0)
105Size of destination file => int(0)
106
107-- Iteration 4 --
108Copy operation => bool(true)
109Existence of destination file => bool(true)
110Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp
111Size of source file => int(0)
112Size of destination file => int(0)
113
114-- Iteration 5 --
115Copy operation => bool(true)
116Existence of destination file => bool(true)
117Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp
118Size of source file => int(0)
119Size of destination file => int(0)
120
121-- Iteration 6 --
122Copy operation => bool(true)
123Existence of destination file => bool(true)
124Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp
125Size of source file => int(0)
126Size of destination file => int(0)
127
128-- Iteration 7 --
129Copy operation => bool(true)
130Existence of destination file => bool(true)
131Destination file name is => %s/copy_variation6/copy_variation6_sub///../*
132Size of source file => int(0)
133Size of destination file => int(0)
134
135-- Iteration 8 --
136Copy operation => bool(true)
137Existence of destination file => bool(true)
138Destination file name is => %s/copy_variation6/copy_variation6_sub/copy variation6/copy_copy_variation6.tmp
139Size of source file => int(0)
140Size of destination file => int(0)
141*** Done ***
142