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