Home > php教程 > php手册 > 浅析is_writable的php实现

浅析is_writable的php实现

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:48:22
Original
914 people have browsed it

以下函数可用于替换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;
        }
    }
}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template