Is_writeable function bug

Source: Internet
Author: User
: 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.