: This article mainly introduces the bug issue of the is_writeable function. if you are interested in the PHP Tutorial, please refer to it. [Question] PHP's is_writeable () function has a Bug and cannot accurately determine whether a directory/file can be written. please write a function to determine whether the directory/file is absolutely writable.
Level 6
[Solution] The following describes the is_really_writable function solution in CodeIgniter. for details, see function comments.
The bug has two aspects,
1. in windowns, the is_writeable () function returns false only when the file is read-only. if true is returned, the file may not be writable.
If it is a directory, create a file in the directory and open the file to determine;
If it is a file, you can test whether the file can be written by opening the file (fopen.
2. in Unix, when safe_mode is enabled in the php configuration file (safe_mode = on), is_writeable () is also unavailable.
Whether to enable safe_mode when reading the configuration file.
/** * Tests for file writability * * is_writable() returns TRUE on Windows servers when you really can't write to * the file, based on the read-only attribute. is_writable() is also unreliable * on Unix servers if safe_mode is on. * * @access private * @return void */if ( ! function_exists('is_really_writable')){ functionis_really_writable($file) {// If we're on a Unix server with safe_mode off we call is_writableif (DIRECTORY_SEPARATOR == '/'AND @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) { returnFALSE; } fclose($fp); @chmod($file, DIR_WRITE_MODE); @unlink($file); returnTRUE; } elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) { returnFALSE; } fclose($fp); returnTRUE; }}
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the is_writeable function bug, including some content, and hope to be helpful to friends who are interested in PHP tutorials.