/**
 * Check if a file has write permissions
 *
 * @param	string	$file	The path to the file to be checked
 * @return	bool	True if it can be written; false if it cannot
 */
function is_file_writable($file)
{
    if (strtolower(substr(PHP_OS, 0, 3)) === 'win' or !function_exists('is_writable')) {
        if (file_exists($file)) {
            // Canonicalise path to absolute path
            if (is_dir($file)) {
                // Test directory by creating a file inside the directory
                $result = @tempnam($file, 'i_w');
                if (is_string($result) and file_exists($result)) {
                    unlink($result);
                    // Ensure the file is actually in the directory (returned realpathed)
                    return strpos($result, $file) === 0 ? true : false;
                }
            } else {
                $handle = @fopen($file, 'r+');
                if (is_resource($handle)) {
                    fclose($handle);
                    return true;
                }
            }
        } else {
            // file does not exist test if we can write to the directory
            $dir = dirname($file);
            if (file_exists($dir) and is_dir($dir) and is_file_writable($dir)) {
                return true;
            }
        }
        return false;
    } else {
        return is_writable($file);
    }
}
Ejemplo n.º 2
0
    $fail_img = '<img src="./images/reserve_tab_unchecked.png" alt="" />';
    $configwrite = false;
    $cachewrite = false;
    $includewrite = false;
    $functionswrite = false;
    $dbcheck = false;
    if (is_file_writable(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "includes" . DIRECTORY_SEPARATOR . "config.new.php")) {
        $configwrite = true;
    }
    if (is_file_writable(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR)) {
        $cachewrite = true;
    }
    if (is_file_writable(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "includes" . DIRECTORY_SEPARATOR)) {
        $includewrite = true;
    }
    if (is_file_writable(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "includes" . DIRECTORY_SEPARATOR . "functions" . DIRECTORY_SEPARATOR . "integrations" . DIRECTORY_SEPARATOR)) {
        $functionswrite = true;
    }
    // Disabling the mySQL database check for now
    //if (checkDB())
    //{
    $dbcheck = true;
    //}
    require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "layout" . DIRECTORY_SEPARATOR . "pages_requirements.php";
    if ($configwrite and $cachewrite and $includewrite and $dbcheck and $functionswrite) {
        $next = array('0' => 'Next', '1' => 'onClick="window.location.href=\'?mode=database\';"');
    } else {
        $next = array('0' => 'Test Again', '1' => 'onClick="window.location.reload();this.className=\'buttondown\'"');
    }
}
// ######################### START DATABASE SETUP ##########################