An example Analysis of the existence of Bug in is_writeable () function in PHP
This article mainly introduces the example analysis of the existence of Bug in the is_writeable () function in PHP, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Bug exists in the is_writeable () function of PHP, so it is impossible to accurately judge whether a directory / file is writable. Please write a function to determine whether a directory / file is absolutely writable.
A: there are two aspects of bug
1) in windowns, the is_writeable () function returns false when the file has only read-only attributes, 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 is enabled in the php configuration file (safe_mode=on), is_writeable () is also not available.
Read whether the configuration file is enabled or not safe_mode.
/ * * 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') {function is_really_writable ($file) {/ / If we're on a Unix server with safe_mode off we call is_writable if (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 (1100). Mt_rand (1100)); 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 FALSE;} fclose ($fp); return TRUE }} Thank you for reading this article carefully. I hope the article "sample Analysis of the existence of Bug in the is_writeable () function in PHP" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!