PHP WebDAV服务器无法使用Windows执行PUT方法

时间:2012-08-23 13:57:38

标签: php windows-7 webdav

我正在尝试实现基于PHP的WebDAV服务器,以便能够在OS Windows(更准确地说是Windows 7)下使用它。

除PUT方法外,一切正常。当我尝试将文件从文件系统上传到WebDAV服务器时,请求content-lenght为空,这意味着我无法读取我想要放入服务器的文件。

以下是使用Windows拖动文件(简单.txt文件)时收到的信息:

[HTTP_USER_AGENT] => Microsoft-WebDAV-MiniRedir/6.1.7601
[HTTP_TRANSLATE] => f
[CONTENT_LENGTH] => 0
[HTTP_VIA] => 1.1 squid.Sole:3128 (squid/2.7.STABLE9), 1.0 squidcache.Proxy6.CCSP:3129 (squid/2.6.STABLE24)
[PATH] => /bin:/usr/bin:/sbin:/usr/sbin
[SERVER_SOFTWARE] => Apache
[SERVER_PORT] => 80
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.0
[REQUEST_METHOD] => PUT

使用专用的webdav客户端上传相同的文件,我得到一个有效的响应,并且正在上传文件。以下是我使用Cyber​​Duck客户端的内容:

[HTTP_EXPECT] => 100-continue
[CONTENT_LENGTH] => 263
[CONTENT_TYPE] => text/plain
[HTTP_CONNECTION] => Keep-Alive
[HTTP_USER_AGENT] => Cyberduck/4.2.1 (9350) (Windows 7/6.1) (x86)
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[PATH] => /bin:/usr/bin:/sbin:/usr/sbin
[SERVER_SOFTWARE] => Apache
[SERVER_PORT] => 80
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => PUT

CONTENT-LENGTH字段已更改,文件在服务器上处于联机状态。 我将在此处发布我的代码片段:

$options = Array();
$options["path"] = $this->path;
$options["content_length"] = $_SERVER["CONTENT_LENGTH"];
$options["stream"] = fopen('php://input', 'r');

$stat = $this->PUT($options); // In the PUT method I fopen the destination file in "w"

if ($stat === false) {
    $stat = "403 Forbidden";
} else if (is_resource($stat) && get_resource_type($stat) == "stream") {
    $stream = $stat;

    $stat = $options["new"] ? "201 Created" : "204 No Content";
    if (!empty($options["ranges"])) {
        if (0 == fseek($stream, $range[0]["start"], SEEK_SET)) {
            $length = $range[0]["end"]-$range[0]["start"]+1;
            if (!fwrite($stream, fread($options["stream"], $length))) {
                 $stat = "403 Forbidden"; 
            }
        } else {
            $stat = "403 Forbidden"; 
        }
    }else {
        while (!feof($options["stream"])) {
            if (false === fwrite($stream, fread($options["stream"], 4096))) { //The fread reads nothing from the stream...
                $stat = "403 Forbidden"; 
                break;
            }
         }
      }
    fclose($stream);    
}

我该怎么做才能解决这个问题?是否有任何东西要在Windows中设置才能使其工作,或者只是我的代码缺少某些东西?

1 个答案:

答案 0 :(得分:0)

Windows将首先创建一个0字节的文件。成功后,它将上传整个文件。