Php is_writable checks whether the file can write instance code,
Introduction to php is_writable Functions
Is_writable-determines whether a given file name can be written. The result of this function will be cached. Use clearstatcache () to clear the cache.
Syntax:
Bool is_writable (string $ filename)
Returns TRUE if the file exists and is writable. The filename parameter can be a directory name that allows write check.
Remember, PHP may only use the user name (usually 'nobody') that runs webserver to access the file. This parameter is not included in the security mode.
Parameters:
The name of the file to be checked.
Return Value:
Returns TRUE if the filename file exists and can be written.
Php is_writable instance
Use the is_writable function to determine whether the given file is readable:
<? Php $ filename = "test. text "; if (is_readable ($ filename) {echo" File $ filename readable ";} else {echo" File $ filename unreadable ";}?>
In fact, we can also write a function to determine whether the file is readable without using the php built-in function is_writable. The following functions can be used to replace the built-in is_writable function in php. For details, refer:
// It can be used to replace the built-in is_writable function isWritable ($ filename) {if (preg_match ('/\/$/', $ filename) of php )) {$ tmp_file = sprintf ('% s. tmp ', $ filename, uniqid (mt_rand (); return isWritable ($ tmp_file);} if (file_exists ($ filename) {// if the file already exists, enable $ fp = @ fopen ($ filename, 'r + ') in read/write mode; if ($ fp) {fclose ($ fp); return true ;} else {return false ;}} else {$ fp = @ fopen ($ filename, 'w'); if ($ fp) {fclose ($ fp ); unlink ($ filename); return true;} else {return false ;}}}
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!