1--TEST--
2Test copy() function: usage variations - destination file names(white spaces)
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip only 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: In creation of destination file names containing white spaces
16     and checking the existence and size of destination files
17*/
18
19echo "*** Test copy() function: destination file names containing whitespaces ***\n";
20$file_path = dirname(__FILE__);
21$src_file_name = $file_path."/copy_variation3.tmp";
22$file_handle = fopen($src_file_name, "w");
23fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
24fclose($file_handle);
25
26/* array of destination file names */
27$dest_files = array(
28
29  /* File names containing whitespaces */
30  "copy variation3.tmp",  //file name containing blank space
31  " copy_variation3.tmp",  //file name starts with blank space
32  "copy\tvariation3.tmp",
33  " ",  //blank space as file name
34);
35
36echo "Size of the source file before copy operation => ";
37var_dump( filesize("$src_file_name") );
38clearstatcache();
39
40echo "\n-- Now applying copy() on source file to create copies --";
41$count = 1;
42foreach($dest_files as $dest_file) {
43
44  echo "\n-- Iteration $count --\n";
45  $dest_file_name = $dest_file;
46
47  echo "Copy operation => ";
48  var_dump( copy($src_file_name, $dest_file_name) );
49
50  echo "Existence of destination file => ";
51  var_dump( file_exists($dest_file_name) );
52
53  if( file_exists($dest_file_name) ) {
54    echo "Destination file name => ";
55    print($dest_file_name);
56    echo "\n";
57
58    echo "Size of source file => ";
59    var_dump( filesize($src_file_name) );
60    clearstatcache();
61
62    echo "Size of destination file => ";
63    var_dump( filesize($dest_file_name) );
64    clearstatcache();
65
66    unlink($dest_file_name);
67  }
68  $count++;
69}
70
71echo "*** Done ***\n";
72?>
73--CLEAN--
74<?php
75unlink(dirname(__FILE__)."/copy_variation3.tmp");
76?>
77--EXPECTF--
78*** Test copy() function: destination file names containing whitespaces ***
79Size of the source file before copy operation => int(1500)
80
81-- Now applying copy() on source file to create copies --
82-- Iteration 1 --
83Copy operation => bool(true)
84Existence of destination file => bool(true)
85Destination file name => copy variation3.tmp
86Size of source file => int(1500)
87Size of destination file => int(1500)
88
89-- Iteration 2 --
90Copy operation => bool(true)
91Existence of destination file => bool(true)
92Destination file name =>  copy_variation3.tmp
93Size of source file => int(1500)
94Size of destination file => int(1500)
95
96-- Iteration 3 --
97Copy operation =>
98Warning: copy(%s): %s
99bool(false)
100Existence of destination file => bool(false)
101
102-- Iteration 4 --
103Copy operation =>
104Warning: copy(%s): %s
105bool(false)
106Existence of destination file => bool(false)
107*** Done ***
108