Skip to content

Instantly share code, notes, and snippets.

@sivel
Created April 13, 2010 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/364940 to your computer and use it in GitHub Desktop.
Save sivel/364940 to your computer and use it in GitHub Desktop.
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