2 /* Prototype: bool copy ( string $source, string $dest );
3 Description: Makes a copy of the file source to dest.
4 Returns TRUE on success or FALSE on failure.
7 /* Test copy() function: In creation of destination file names containing special characters
8 and checking the existence and size of destination files
11 echo "*** Test copy() function: destination file names containing special characters ***\n";
12 $file_path = dirname(__FILE__
);
13 $src_file_name = $file_path."/copy_variation2.tmp";
14 $file_handle = fopen($src_file_name, "w");
15 fwrite( $file_handle, str_repeat(b
"Hello2World...\n", 100) );
18 /* array of destination file names */
21 /* File names containing special(non-alpha numeric) characters */
22 "_copy_variation2.tmp",
23 "@copy_variation2.tmp",
24 "#copy_variation2.tmp",
25 "+copy_variation2.tmp",
26 "?copy_variation2.tmp",
27 ">copy_variation2.tmp",
28 "!copy_variation2.tmp",
29 "©_variation2.tmp",
30 "(copy_variation2.tmp",
31 ":copy_variation2.tmp",
32 ";copy_variation2.tmp",
33 "=copy_variation2.tmp",
34 "[copy_variation2.tmp",
35 "^copy_variation2.tmp",
36 "{copy_variation2.tmp",
37 "|copy_variation2.tmp",
38 "~copy_variation2.tmp",
39 "\$copy_variation2.tmp"
42 echo "Size of the source file before copy operation => ";
43 var_dump( filesize("$src_file_name") );
46 echo "\n--- Now applying copy() on source file to create copies ---";
48 foreach($dest_files as $dest_file) {
49 echo "\n-- Iteration $count --\n";
50 $dest_file_name = $file_path."/$dest_file";
52 echo "Copy operation => ";
53 var_dump( copy($src_file_name, $dest_file_name) );
55 echo "Existence of destination file => ";
56 var_dump( file_exists($dest_file_name) );
58 if( file_exists($dest_file_name) ) {
59 echo "Destination file name => ";
60 print($dest_file_name);
63 echo "Size of source file => ";
64 var_dump( filesize($src_file_name) );
67 echo "Size of destination file => ";
68 var_dump( filesize($dest_file_name) );
71 unlink($dest_file_name);
76 echo "*** Done ***\n";
79 unlink(dirname(__FILE__
)."/copy_variation2.tmp");