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/* 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 "*** Testing copy() function: copying data file across directories ***\n";
19$base_dir = dirname(__FILE__)."/copy_variation16";
20mkdir($base_dir);
21
22$sub_dir = $base_dir."/copy_variation16_sub";
23mkdir($sub_dir);
24
25$dirname_with_blank = $sub_dir."/copy variation16";
26mkdir($dirname_with_blank);
27
28$src_file_name = dirname(__FILE__)."/copy_variation16.tmp";
29$file_handle = fopen($src_file_name, "w");
30fwrite($file_handle, str_repeat(b"Hello world, this is 2007 year ...\n", 100));
31fclose($file_handle);
32
33echo "- Size of source file => ";
34var_dump( filesize($src_file_name) );
35clearstatcache();
36
37$dests = array(
38  $base_dir."/copy_copy_variation16.tmp",
39  $base_dir."/copy_variation16_sub/copy_copy_variation16.tmp",
40  "$sub_dir/copy_copy_variation16.tmp",
41  "$sub_dir/../copy_copy_variation16.tmp",
42  "$sub_dir/../copy_variation16_sub/copy_copy_variation16.tmp",
43  "$sub_dir/..///../copy_copy_variation16.tmp",
44  "$sub_dir/..///../*",
45  "$dirname_with_blank/copy_copy_variation16.tmp"
46);
47
48echo "\n--- Now applying copy() on source file to create copies ---";
49$count = 1;
50foreach($dests as $dest) {
51  echo "\n-- Iteration $count --\n";
52
53  echo "Size of source file => ";
54  var_dump( filesize($src_file_name) );
55
56  echo "Copy operation => ";
57  var_dump( copy($src_file_name, $dest) );
58
59  echo "Existence of destination file => ";
60  var_dump( file_exists($dest) );
61
62  if( file_exists($dest) ){
63    echo "Destination file name is => ";
64    print($dest);
65    echo "\n";
66
67    echo "Size of destination file => ";
68    var_dump( filesize($dest) );
69    clearstatcache();
70
71    unlink("$dest");
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*** Testing copy() function: copying data file across directories ***
86- Size of source file => int(3500)
87
88--- Now applying copy() on source file to create copies ---
89-- Iteration 1 --
90Size of source file => int(3500)
91Copy operation => bool(true)
92Existence of destination file => bool(true)
93Destination file name is => %s/copy_variation16/copy_copy_variation16.tmp
94Size of destination file => int(3500)
95
96-- Iteration 2 --
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 3 --
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 4 --
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_copy_variation16.tmp
115Size of destination file => int(3500)
116
117-- Iteration 5 --
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_variation16_sub/copy_copy_variation16.tmp
122Size of destination file => int(3500)
123
124-- Iteration 6 --
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/..///../copy_copy_variation16.tmp
129Size of destination file => int(3500)
130
131-- Iteration 7 --
132Size of source file => int(3500)
133Copy operation =>
134Warning: copy(%s): failed to open stream: No such file or directory in %s on line %s
135bool(false)
136Existence of destination file => bool(false)
137
138-- Iteration 8 --
139Size of source file => int(3500)
140Copy operation => bool(true)
141Existence of destination file => bool(true)
142Destination file name is => %s/copy_variation16/copy_variation16_sub/copy variation16/copy_copy_variation16.tmp
143Size of destination file => int(3500)
144*** Done ***
145