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