win_is_writable

Workaround for Windows bug in is_writable() function.

Description

win_is_writable( (string) $path ); 

PHP has issues with Windows ACL's for determine if a directory is writable or not, this works around them by checking the ability to open files rather than relying upon PHP to interprate the OS ACL.

Parameters (1)

0. $path (string)
Windows path to check for write-ability.

Usage

  1. if ( !function_exists( 'win_is_writable' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Windows path to check for write-ability. 
  5. $path = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = win_is_writable($path); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function win_is_writable( $path ) { 
  2.  
  3. if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory 
  4. return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); 
  5. } elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory 
  6. return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); 
  7. // check tmp file for read/write capabilities 
  8. $should_delete_tmp_file = !file_exists( $path ); 
  9. $f = @fopen( $path, 'a' ); 
  10. if ( $f === false ) 
  11. return false; 
  12. fclose( $f ); 
  13. if ( $should_delete_tmp_file ) 
  14. unlink( $path ); 
  15. return true;