win_is_writable

Definition:
function win_is_writable( $path ) {}

Workaround for Windows bug in is_writable() function

Parameters

  • string $path

Source code

function win_is_writable( $path ) {

	/* will work in despite of Windows ACLs bug

	 * NOTE: use a trailing slash for folders!!!

	 * see http://bugs.php.net/bug.php?id=27609

	 * see http://bugs.php.net/bug.php?id=30931

	 */



	if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path

		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');

	else if ( is_dir( $path ) )

		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );

	// check tmp file for read/write capabilities

	$should_delete_tmp_file = !file_exists( $path );

	$f = @fopen( $path, 'a' );

	if ( $f === false )

		return false;

	fclose( $f );

	if ( $should_delete_tmp_file )

		unlink( $path );

	return true;

}

3357

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: