1--TEST-- 2Test copy() function: usage variations - destination dir access perms 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == 'WIN') 6 die("skip do not run on Windows"); 7// Skip if being run by root (files are always readable, writeable and executable) 8$filename = dirname(__FILE__)."/copy_variation15_root_check.tmp"; 9$fp = fopen($filename, 'w'); 10fclose($fp); 11if(fileowner($filename) == 0) { 12 unlink ($filename); 13 die('skip cannot be run as root'); 14} 15unlink($filename); 16?> 17--FILE-- 18<?php 19/* Prototype: bool copy ( string $source, string $dest ); 20 Description: Makes a copy of the file source to dest. 21 Returns TRUE on success or FALSE on failure. 22*/ 23 24/* Test copy(): Trying to create a copy of file in a dir which doesn't have write permissions */ 25 26$file_path = dirname(__FILE__); 27 28echo "*** Test copy() function: Trying to create a copy of file in a dir which doesn't have write permissions ***"; 29$file = $file_path."/copy_variation15.tmp"; 30$file_handle = fopen($file, "w"); 31fwrite($file_handle, str_repeat(b"Hello, world...", 20)); 32fclose($file_handle); 33 34$dir = $file_path."/copy_variation15"; 35mkdir($dir); 36 37$old_perms = fileperms($dir); 38 39chmod($dir, 0555); //dir without write permissions 40 41$dest = $dir."/copy_copy_variation15.tmp"; 42 43var_dump( copy($file, $dir."/copy_copy_variation15.tmp") ); 44var_dump( file_exists($dir."/copy_copy_variation15_dir.tmp") ); 45var_dump( filesize($file) ); //size of source 46 47chmod($dir, $old_perms); 48 49echo "*** Done ***\n"; 50?> 51--CLEAN-- 52<?php 53unlink(dirname(__FILE__)."/copy_variation15.tmp"); 54rmdir(dirname(__FILE__)."/copy_variation15"); 55?> 56--EXPECTF-- 57*** Test copy() function: Trying to create a copy of file in a dir which doesn't have write permissions *** 58Warning: copy(%s): %s 59bool(false) 60bool(false) 61int(300) 62*** Done *** 63