PHP函数is_writeable非常奇怪的行为。

本文介绍了一个用于检查PHP环境中特定文件及目录读写权限的脚本。该脚本通过修改文件权限并验证其是否具备必要的读写能力来确保PHP应用能够正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我写的PHP代码如下:testfile.php

<?php
    $writeok = array("uploads/", "cache/", "templates_c/", "mainfile.php");
    $title = "test file php";
    $content = "<table align='center'><tr><td align='left'>/n";
    $error = false;
    foreach ($writeok as $wok) {
            echo "<br />"."../".$wok."<br />";
          echo fileowner("../".$wok)."<br />";
          echo filegroup("../".$wok)."<br />";
      echo fileowner("../".$wok)."<br />";
      echo substr(sprintf('%o', fileperms("../".$wok)), -4)."<br />";
          echo filetype("../".$wok)."<br />";
          
        if (!is_dir("../".$wok)) {

          
            if ( file_exists("../".$wok) ) {
        @chgrp("../".$wok, fileowner("../".$wok));
                @chmod("../".$wok, 0666);
                if (is_writeable("../".$wok)==false) {
                    $content .= "file ".$wok." is not writeable"."<br />";
                    $error = true;
                  
                }else{
                    $content .=  "file ".$wok."  is  writeable"."<br />";
                }
                if (!is_readable("../".$wok)) {
                    $content .= "file ".$wok."  is not readable"."<br />";
                    $error = true;
                  
                }else{
                    $content .=  "file ".$wok."  is  readable"."<br />";
                }
               
            }
        } else {
      @chgrp("../".$wok, fileowner("../".$wok));
            @chmod("../".$wok, 0777);
            if (!is_writeable("../".$wok)) {
                $content .=  "dir ".$wok." is not writeable"."<br />";
                $error = true;
               
            }else{
                $content .=   "dir ".$wok."is writeable"."<br />";
            }
            if (!is_readable("../".$wok)) {
                $content .= "dir ".$wok." is not readable"."<br />";
                $error = true;
                  
            }else{
                    $content .=  "dir ".$wok." is  readable"."<br />";
            }           
        }
    }
    $content .= "</td></tr></table>/n";

    if(! $error) {
        $content .= "<p>"."not error"."</p>";
       
       
    }else{
        $content .= "<p>"." error "."</p>";
       
    }

    echo $content;

    ?>

 

可是执行结果非常奇怪:

../uploads/
0
0
0
0777
dir

../cache/
0
0
0
0777
dir

../templates_c/
0
0
0
0777
dir

../mainfile.php
0
0
0
0666
file

dir uploads/ is not writeable
dir uploads/ is readable
dir cache/ is not writeable
dir cache/ is readable
dir templates_c/ is not writeable
dir templates_c/ is readable
file mainfile.php is not writeable
file mainfile.php is readable

error

 到底是什么原因?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值