Exemplo n.º 1
0
 /**
  * Contructor
  */
 public function __construct()
 {
     global $mangareader_root_path;
     $this->cache_dir = $mangareader_root_path . 'cache/';
     if (!reader_is_writable($this->cache_dir)) {
         $this->not_writable = true;
         trigger_error('CACHE_NOT_WRITABLE', E_WARNING);
     }
 }
Exemplo n.º 2
0
/**
* Check if path is writable
*
* This will work for both *nix and windows systems
* @see https://bugs.php.net/bug.php?id=27609
* @see https://bugs.php.net/bug.php?id=30931
*
* @param string $path Use trailing slash for folders!
* @return boolean Either true if the path is writable or false if it is not
*/
function reader_is_writable($path)
{
    if (strtolower(substr(PHP_OS, 0, 3)) == 'win' || !function_exists('is_writable')) {
        if (file_exists($path)) {
            $path = realpath($path);
            if (is_dir($path)) {
                // Try creating a new file in directory
                $result = @tempnam($path, 'i_w');
                if (is_string($result) && file_exists($result)) {
                    unlink($result);
                    // Ensure the file is actually in the directory
                    return strpos($result, $path) === 0 ? true : false;
                }
            } else {
                $handle = @fopen($path, 'r+');
                if (is_resource($handle)) {
                    fclose($handle);
                    return true;
                }
            }
        } else {
            // file does not exist test if we can write to the directory
            $dir = dirname($path);
            if (file_exists($dir) && is_dir($dir) && reader_is_writable($dir)) {
                return true;
            }
        }
        return false;
    } else {
        return is_writable($path);
    }
}