1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
--TEST--
Test copy() function: usage variations - destination file names(special chars)
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip only run on Windows");
?>
--FILE--
<?php
/* Prototype: bool copy ( string $source, string $dest );
Description: Makes a copy of the file source to dest.
Returns TRUE on success or FALSE on failure.
*/
/* Test copy() function: In creation of destination file names containing special characters
and checking the existence and size of destination files
*/
echo "*** Test copy() function: destination file names containing special characters ***\n";
$file_path = dirname(__FILE__);
$src_file_name = $file_path."/copy_variation2.tmp";
$file_handle = fopen($src_file_name, "w");
fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
fclose($file_handle);
/* array of destination file names */
$dest_files = array(
/* File names containing special(non-alpha numeric) characters */
"_copy_variation2.tmp",
"@copy_variation2.tmp",
"#copy_variation2.tmp",
"+copy_variation2.tmp",
"?copy_variation2.tmp",
">copy_variation2.tmp",
"!copy_variation2.tmp",
"©_variation2.tmp",
"(copy_variation2.tmp",
":copy_variation2.tmp",
";copy_variation2.tmp",
"=copy_variation2.tmp",
"[copy_variation2.tmp",
"^copy_variation2.tmp",
"{copy_variation2.tmp",
"|copy_variation2.tmp",
"~copy_variation2.tmp",
"\$copy_variation2.tmp"
);
echo "Size of the source file before copy operation => ";
var_dump( filesize("$src_file_name") );
clearstatcache();
echo "\n--- Now applying copy() on source file to create copies ---";
$count = 1;
foreach($dest_files as $dest_file) {
echo "\n-- Iteration $count --\n";
$dest_file_name = $file_path."/$dest_file";
echo "Copy operation => ";
var_dump( copy($src_file_name, $dest_file_name) );
echo "Existence of destination file => ";
var_dump( file_exists($dest_file_name) );
if( file_exists($dest_file_name) ) {
echo "Destination file name => ";
print($dest_file_name);
echo "\n";
echo "Size of source file => ";
var_dump( filesize($src_file_name) );
clearstatcache();
echo "Size of destination file => ";
var_dump( filesize($dest_file_name) );
clearstatcache();
unlink($dest_file_name);
}
$count++;
}
echo "*** Done ***\n";
?>
--CLEAN--
<?php
unlink(dirname(__FILE__)."/copy_variation2.tmp");
?>
--EXPECTF--
*** Test copy() function: destination file names containing special characters ***
Size of the source file before copy operation => int(1500)
--- Now applying copy() on source file to create copies ---
-- Iteration 1 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/_copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 2 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/@copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 3 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/#copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 4 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/+copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 5 --
Copy operation =>
Warning: copy(%s): %s
bool(false)
Existence of destination file => bool(false)
-- Iteration 6 --
Copy operation =>
Warning: copy(%s): %s
bool(false)
Existence of destination file => bool(false)
-- Iteration 7 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/!copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 8 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/©_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 9 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/(copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 10 --
Copy operation =>
Warning: copy(%s): %s
bool(false)
Existence of destination file => bool(false)
-- Iteration 11 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/;copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 12 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/=copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 13 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/[copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 14 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/^copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 15 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/{copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 16 --
Copy operation =>
Warning: copy(%s): %s
bool(false)
Existence of destination file => bool(false)
-- Iteration 17 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/~copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 18 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/$copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
*** Done ***
|