copy_variation15.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. Test copy() function: usage variations - destination dir 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_variation15_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 create a copy of file in a dir which doesn't have write permissions */
  24. $file_path = dirname(__FILE__);
  25. echo "*** Test copy() function: Trying to create a copy of file in a dir which doesn't have write permissions ***";
  26. $file = $file_path."/copy_variation15.tmp";
  27. $file_handle = fopen($file, "w");
  28. fwrite($file_handle, str_repeat(b"Hello, world...", 20));
  29. fclose($file_handle);
  30. $dir = $file_path."/copy_variation15";
  31. mkdir($dir);
  32. $old_perms = fileperms($dir);
  33. chmod($dir, 0555); //dir without write permissions
  34. $dest = $dir."/copy_copy_variation15.tmp";
  35. var_dump( copy($file, $dir."/copy_copy_variation15.tmp") );
  36. var_dump( file_exists($dir."/copy_copy_variation15_dir.tmp") );
  37. var_dump( filesize($file) ); //size of source
  38. chmod($dir, $old_perms);
  39. echo "*** Done ***\n";
  40. ?>
  41. --CLEAN--
  42. <?php
  43. unlink(dirname(__FILE__)."/copy_variation15.tmp");
  44. rmdir(dirname(__FILE__)."/copy_variation15");
  45. ?>
  46. --EXPECTF--
  47. *** Test copy() function: Trying to create a copy of file in a dir which doesn't have write permissions ***
  48. Warning: copy(%s): %s
  49. bool(false)
  50. bool(false)
  51. int(300)
  52. *** Done ***