Skip to content

Instantly share code, notes, and snippets.

@sivel
Created Apr 13, 2010
Embed
What would you like to do?
Test for the minimum file permissions required for the webserver to read a file that it has written
<?php
function perm_test() {
$file = '.perm_test';
@touch( $file );
if ( ! is_readable( $file ) )
return false;
$perms = array( 0666, 0664, 0644, 0660, 0640, 0600, 0444, 0440, 0400 );
$lastperm = 0666;
foreach ( $perms as $perm ) {
if ( ! @chmod( $file, $perm ) )
return false;
if ( ! is_readable( $file ) )
return $lastperm;
$lastperm = $perm;
}
@unlink( $file );
return $lastperm;
}
var_dump(decoct(wp_perm_test()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment