为什么对于URL路径而言is_readable&is_writable&file_exists失败而对同一目录中的文件失败?

n8g*_*ard 2 php file-io file-permissions

我一直在谷歌搜索这个问题两天,真的没有找到能给我一个坚实答案的人.也许stackoverflow的天才可以帮忙吗?

我的难题:我正在尝试使用URL语法读取和写入文件,指向我服务器上的文件的URL.(参见下面的代码)只要文件名与php文件位于同一目录中,并且我没有在其上使用任何URL套接字,代码就可以正常工作.(即$ filename ="test.xml")但是一旦我尝试添加一个URL套接字(即http://127.0.0.1/site_folder/text.xml),我就会在所有三个测试中失败(is_readable,is_writable,文件已存在).为什么会这样?有没有办法纠正它,以便我可以读写这个文件?

我的安装程序:Microsoft Vista上的Microsoft IIS 7.0.6000.16386上的PHP 5.3.2 PHP目录:c:\ Program Files(x86)\ php\Security:我已设置文件目录和文件本身的权限IUSR帐户可以读取,写入,执行,列出目录.此php文件暂时与test.xml文件位于同一目录中.但我想让这个URL工作,以便我将来可以在不同的目录中调整文件.

php.ini config:我尝试过这些设置:

open_basedir=Off; 
fastcgi.impersonate = 1;
display_errors = On;
error_reporting = E_ALL & ~E_STRICT;
safe_mode = Off;
allow_url_fopen = Off; (and tried On, neither works);
allow_url_include = Off; (and tried On, neither works);
Run Code Online (Sandbox Code Playgroud)

这是我的简单代码示例:

<?php
        $filename = "http://127.0.0.1/sitename/admin/interface/test.xml"; // this one fails
//      $filename = "text.xml" // this one works fine
    echo $filename;

        if (is_readable($filename)) {
                echo "<br />The file is readable...<br />";
        } else {
                echo "<br />The file is not readable...<br />";
        }

        if (is_writable($filename)) {
                echo "The file is writable...<br />";
        } else {
                echo "The file is not writable...<br />";
        }

        if (file_exists($filename)) { 
                echo "File exists...<br />";
        } else {
                echo "File cannot be found...<br />";
        }
?>
Run Code Online (Sandbox Code Playgroud)

我得到的输出:

http://127.0.0.1/sitename/admin/interface/test.xml
The file is not readable...
The file is not writable...
File cannot be found...
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?作为旁注,在我的Macbook Pro上使用Apache服务器上的PHP 5.3.2也会发生同样的事情.

dbe*_*zzi 5

http://协议包装器不支持stat()系列函数(请参阅:http://php.net/manual/wrappers.http.php以查看支持的内容).stat_exists,is_writable和is_readable需要stat()支持.

file://协议包装器(在您的工作示例中使用的默认包装器)支持stat():http://php.net/manual/wrappers.file.php

您可以在此处阅读有关协议和包装器的更多信息:http: //php.net/manual/wrappers.php