2014-09-27, 06:48 AM
Hello. I need a little help from you (again).
I want to make sure a directory (NOT a file) is NOT writable.
Here's my attempt:
Is there any other better way to do this?
I want to make sure a directory (NOT a file) is NOT writable.
Here's my attempt:
// Attempt to determine if a directory is NOT writable
$dir = MYBB_ROOT."my_dir/"; // directory path (in MYBB_ROOT)
@fopen($dir.'test.txt', 'w'); // create and open 'test.txt' file in writable mode
if(@file_exists($dir.'test.txt', 'w')) // if 'test.txt' file has been created
{
@fclose($dir.'test.txt'); // close file
@unlink($dir.'test.txt'); // delete file
@my_chmod($dir, '0755'); // attempt to change the chmod for '$dir' to "0755"
// a second test
@fopen($dir.'test.txt', 'w'); // create and open 'test.txt' file in writable mode
if(@file_exists($dir.'test.txt')) // if 'test.txt' file has been created
{
@fclose($dir.'test.txt'); // close file
@unlink($dir.'test.txt'); // delete file
exit("The directory is writable."); // stop the script and output a message
}
}
// the directory is NOT writable
echo "The directory is NOT writable.";
exit();
Is there any other better way to do this?