The is_writeable () function of the
topic PHP has a bug that does not accurately determine whether a directory/file is writable, write a function to determine if the directory/file is absolutely writable.
Level Six
"resolve" is the Is_really_writable function solution in CodeIgniter, as described in the function note
where bugs exist in two aspects,
1, in windowns, when files have only read-only properties, The is_writeable () function returns False, and when True is returned, the file is not necessarily writable.
If it is a directory, create a new file in the directory and determine by opening the file;
If it is a file, you can test whether the file is writable by opening the file (fopen).
2, in Unix, when Safe_mode (Safe_mode=on) is opened in the PHP configuration file, is_writeable () is also unavailable. The
reads whether the configuration file is Safe_mode open.
/** * Tests for file writability * * is_writable () returns TRUE on Windows servers while you really can ' t write to * th e file, based on the read-only attribute.
Is_writable () is also unreliable * on Unix servers if Safe_mode. * @access Private * @return void */if (! function_exists (' is_really_writable ')) {function is_really_writable
($file) {//If we ' re on a Unix server with Safe_mode off we call is_writable If (Directory_separator = =
Ini_get ("safe_mode") = = FALSE) {return is_writable ($file); }//For Windows servers and Safe_mode "on" installations we ll actually//write a file then read it. Bah. if (Is_dir ($file)) {$file = RTrim ($file, '/'). '
/'. MD5 (Mt_rand (1,100). Mt_rand (1,100));
if ($fp = @fopen ($file, fopen_write_create)) = = False) {return false;
} fclose ($FP); @chmod ($fIle, Dir_write_mode);
@unlink ($file);
return TRUE; } elseif (! is_file ($file) OR ($fp = @fopen ($file, fopen_write_create)) = = FALSE) {return F
Alse;
} fclose ($FP);
return TRUE; }
}