In PHP, you can use the is_writable () function to determine whether a file/directory is writable, as detailed below:
Reference
Is_writable
(PHP 4, PHP 5)
Is_writable-determines whether a given file name can be written
Description
BOOL Is_writable (String $filename)
Returns TRUE if the file exists and is writable. ($filename parameter can be a directory name that checks whether the directory is writable.) )
Remember that PHP may only be able to access the file by running the webserver user name (usually ' nobody '). Restrictions that do not count toward Safe mode.
Example #1 is_writable () example
<?php$filename = ' Test.txt ', if (is_writable ($filename)) {echo ' The file is writable ';} else {echo ' The file was not writ Able ';}? >
Note: is_writeable () is an alias for is_writable ()!
However, the above function in the PHP4 is a bug, especially under the Windows Server is not allowed, the official related bug report link is as follows:
http://bugs.php.net/bug.php?id=27609
To be compatible with each operating system, you can customize a writable function with the following code:
/** * Determine if the file/directory is writable (replace the system's own is_writeable function) * * @param string $file File/directory * @return Boolean */function new_is_writeable ($ File) {if (Is_dir ($file)) {$dir = $file, if ($fp = @fopen ("$dir/test.txt", ' W ')) {@fclose ($fp); @unlink ("$dir/test.txt"); $ writeable = 1;} else {$writeable = 0;}} else {if ($fp = @fopen ($file, ' A + ')) {@fclose ($fp); $writeable = 1;} else {$writeable = 0;}} return $writeable;}
PHP determines if a file or directory is writable