is_writeable function Bug problem ___ function

Source: Internet
Author: User

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; }
}
Related Article

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.