以下函数可用于替换php内置的is_writable函数

复制代码 代码如下:

//可用于替换php内置的is_writable函数
function isWritable($filename){
    if(preg_match('/\/$/',$filename)){
        $tmp_file=sprintf('%s%s.tmp',$filename,uniqid(mt_rand()));
        return isWritable($tmp_file);
    }
    if(file_exists($filename)){
        //文件已经存在的话,使用读写方式打开
        $fp=@fopen($filename,'r+');
        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;
        }
    }
}

点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部