1--TEST--
2Test copy() function: usage variations - destination file access perms
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) == 'WIN')
6  die("skip do not run on Windows");
7
8// Skip if being run by root (files are always readable, writeable and executable)
9$filename = dirname(__FILE__)."/copy_variation9_root_check.tmp";
10$fp = fopen($filename, 'w');
11fclose($fp);
12if(fileowner($filename) == 0) {
13        unlink ($filename);
14        die('skip cannot be run as root');
15}
16unlink($filename);
17?>
18--FILE--
19<?php
20/* Prototype: bool copy ( string $source, string $dest );
21   Description: Makes a copy of the file source to dest.
22     Returns TRUE on success or FALSE on failure.
23*/
24
25/* Test copy(): Trying to copy source file to destination file with and without write permissions */
26
27$file_path = dirname(__FILE__);
28
29echo "*** Test copy() function: destination with/without write permissions ***\n";
30$src_file_name = $file_path."/copy_variation9.tmp";
31$file_handle =  fopen($src_file_name, "w");
32fwrite($file_handle, str_repeat(b"Hello2world...\n", 100));
33fclose($file_handle);
34
35$dest_file_name =  $file_path."/copy_copy_variation9.tmp";
36
37
38echo "\n-- With write permissions --\n";
39var_dump( file_exists($src_file_name) );
40var_dump( copy($src_file_name, $dest_file_name) );
41var_dump( file_exists($dest_file_name) );
42var_dump( filesize($dest_file_name) );
43
44echo "\n-- Without write permissions --\n";
45chmod($file_path."/copy_copy_variation9.tmp", 0555);  //No write permissions
46var_dump( file_exists($src_file_name) );
47var_dump( copy($src_file_name, $dest_file_name) );
48var_dump( file_exists($dest_file_name) );
49var_dump( filesize($dest_file_name) );
50
51echo "*** Done ***\n";
52?>
53
54--CLEAN--
55<?php
56unlink(dirname(__FILE__)."/copy_copy_variation9.tmp");
57unlink(dirname(__FILE__)."/copy_variation9.tmp");
58?>
59--EXPECTF--
60*** Test copy() function: destination with/without write permissions ***
61
62-- With write permissions --
63bool(true)
64bool(true)
65bool(true)
66int(1500)
67
68-- Without write permissions --
69bool(true)
70
71Warning: %s
72bool(false)
73bool(true)
74int(1500)
75*** Done ***
76