1--TEST--
2Test copy() function: usage variations - copy data file across dirs
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip Run only on Windows");
7?>
8--FILE--
9<?php
10/* Test copy() function: Trying to create copy of source file
11     into different destination dir paths given in various notations */
12
13echo "*** Testing copy() function: copying data file across directories ***\n";
14$base_dir = __DIR__."/copy_variation16";
15mkdir($base_dir);
16
17$sub_dir = $base_dir."/copy_variation16_sub";
18mkdir($sub_dir);
19
20$dirname_with_blank = $sub_dir."/copy variation16";
21mkdir($dirname_with_blank);
22
23$src_file_name = __DIR__."/copy_variation16.tmp";
24$file_handle = fopen($src_file_name, "w");
25fwrite($file_handle, str_repeat("Hello world, this is 2007 year ...\n", 100));
26fclose($file_handle);
27
28echo "- Size of source file => ";
29var_dump( filesize($src_file_name) );
30clearstatcache();
31
32$dests = array(
33  $base_dir."/copy_copy_variation16.tmp",
34  $base_dir."/copy_variation16_sub/copy_copy_variation16.tmp",
35  "$sub_dir/copy_copy_variation16.tmp",
36  "$sub_dir/../copy_copy_variation16.tmp",
37  "$sub_dir/../copy_variation16_sub/copy_copy_variation16.tmp",
38  "$sub_dir/..///../copy_copy_variation16.tmp",
39  "$sub_dir///../*",
40  "$dirname_with_blank/copy_copy_variation16.tmp"
41);
42
43echo "\n--- Now applying copy() on source file to create copies ---";
44$count = 1;
45foreach($dests as $dest) {
46  echo "\n-- Iteration $count --\n";
47
48  echo "Size of source file => ";
49  var_dump( filesize($src_file_name) );
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 destination file => ";
63    var_dump( filesize($dest) );
64    clearstatcache();
65
66    unlink("$dest");
67  }
68  $count++;
69}
70
71unlink($src_file_name);
72rmdir($dirname_with_blank);
73rmdir($sub_dir);
74rmdir($base_dir);
75
76echo "*** Done ***\n";
77?>
78--EXPECTF--
79*** Testing copy() function: copying data file across directories ***
80- Size of source file => int(3500)
81
82--- Now applying copy() on source file to create copies ---
83-- Iteration 1 --
84Size of source file => int(3500)
85Copy operation => bool(true)
86Existence of destination file => bool(true)
87Destination file name is => %s/copy_variation16/copy_copy_variation16.tmp
88Size of destination file => int(3500)
89
90-- Iteration 2 --
91Size of source file => int(3500)
92Copy operation => bool(true)
93Existence of destination file => bool(true)
94Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp
95Size of destination file => int(3500)
96
97-- Iteration 3 --
98Size of source file => int(3500)
99Copy operation => bool(true)
100Existence of destination file => bool(true)
101Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp
102Size of destination file => int(3500)
103
104-- Iteration 4 --
105Size of source file => int(3500)
106Copy operation => bool(true)
107Existence of destination file => bool(true)
108Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_copy_variation16.tmp
109Size of destination file => int(3500)
110
111-- Iteration 5 --
112Size of source file => int(3500)
113Copy operation => bool(true)
114Existence of destination file => bool(true)
115Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_variation16_sub/copy_copy_variation16.tmp
116Size of destination file => int(3500)
117
118-- Iteration 6 --
119Size of source file => int(3500)
120Copy operation => bool(true)
121Existence of destination file => bool(true)
122Destination file name is => %s/copy_variation16/copy_variation16_sub/..///../copy_copy_variation16.tmp
123Size of destination file => int(3500)
124
125-- Iteration 7 --
126Size of source file => int(3500)
127Copy operation =>
128Warning: copy(%s): Failed to open stream: No such file or directory in %s on line %d
129bool(false)
130Existence of destination file => bool(false)
131
132-- Iteration 8 --
133Size of source file => int(3500)
134Copy operation => bool(true)
135Existence of destination file => bool(true)
136Destination file name is => %s/copy_variation16/copy_variation16_sub/copy variation16/copy_copy_variation16.tmp
137Size of destination file => int(3500)
138*** Done ***
139