copy_variation9.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. Test copy() function: usage variations - destination file access perms
  3. --SKIPIF--
  4. <?php
  5. if(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_variation9_root_check.tmp";
  9. $fp = fopen($filename, 'w');
  10. fclose($fp);
  11. if(fileowner($filename) == 0) {
  12. unlink ($filename);
  13. die('skip cannot be run as root');
  14. }
  15. unlink($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. /* Test copy(): Trying to copy source file to destination file with and without write permissions */
  24. $file_path = dirname(__FILE__);
  25. echo "*** Test copy() function: destination with/without write permissions ***\n";
  26. $src_file_name = $file_path."/copy_variation9.tmp";
  27. $file_handle = fopen($src_file_name, "w");
  28. fwrite($file_handle, str_repeat(b"Hello2world...\n", 100));
  29. fclose($file_handle);
  30. $dest_file_name = $file_path."/copy_copy_variation9.tmp";
  31. echo "\n-- With write permissions --\n";
  32. var_dump( file_exists($src_file_name) );
  33. var_dump( copy($src_file_name, $dest_file_name) );
  34. var_dump( file_exists($dest_file_name) );
  35. var_dump( filesize($dest_file_name) );
  36. echo "\n-- Without write permissions --\n";
  37. chmod($file_path."/copy_copy_variation9.tmp", 0555); //No write permissions
  38. var_dump( file_exists($src_file_name) );
  39. var_dump( copy($src_file_name, $dest_file_name) );
  40. var_dump( file_exists($dest_file_name) );
  41. var_dump( filesize($dest_file_name) );
  42. echo "*** Done ***\n";
  43. ?>
  44. --CLEAN--
  45. <?php
  46. unlink(dirname(__FILE__)."/copy_copy_variation9.tmp");
  47. unlink(dirname(__FILE__)."/copy_variation9.tmp");
  48. ?>
  49. --EXPECTF--
  50. *** Test copy() function: destination with/without write permissions ***
  51. -- With write permissions --
  52. bool(true)
  53. bool(true)
  54. bool(true)
  55. int(1500)
  56. -- Without write permissions --
  57. bool(true)
  58. Warning: %s
  59. bool(false)
  60. bool(true)
  61. int(1500)
  62. *** Done ***