Skip to content

Instantly share code, notes, and snippets.

@Radon8472
Created August 11, 2022 09:57
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 Radon8472/ef94efab1d90e8042326fac54e11b9a4 to your computer and use it in GitHub Desktop.
Save Radon8472/ef94efab1d90e8042326fac54e11b9a4 to your computer and use it in GitHub Desktop.
Tests for php is_writeable function
<?php
/**
* is_writeable-test.php
*
* (on windows is_writeable sometimes returns false, even you have write-permissions, this testfile helps to check this)
*
* @see: https://bugs.php.net/bug.php?id=68926
*
*
* @since 2022-08-11
*/
header('Content-Type: text/plain');
$dir = '.';
$result = file_put_contents("{$dir}/is-this-writeable.txt", 'when you see this, it is writeable');
$realDir = realpath($dir);
if ($result !== false)
echo "Dir '{$realDir }' is writeable" . PHP_EOL;
else
echo "Dir '{$realDir }' NOT is writeable" . PHP_EOL;
echo PHP_EOL . 'Function-results: '
. PHP_EOL . '-------------------------------' . PHP_EOL;
$tests = [
'file_exists' => file_exists($realDir),
'is_writeable' => is_writeable($realDir),
'is_readable' => is_writeable($realDir),
'is_dir' => is_dir($realDir),
'is_file' => is_file($realDir),
'touch' => touch($realDir),
'fileperms' => decoct(fileperms($realDir) & 0777)
];
foreach($tests as $func => $result) {
printf('%-20s: %s'.PHP_EOL, $func, var_export($result, true));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment