Created
April 13, 2010 18:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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