I'm trying to implement a PHP-based WebDAV server to be able to use it under OS Windows (more precisely Windows 7).
Everything works just fine, except for the PUT method. When I try to upload a file from the filesystem to the WebDAV server the request content-lenght is empty, meaning i can't read the file i want to put in the server.
Here is what I'm receiveng when I drag a file (simple .txt file) using Windows:
[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
Uploading the same file using a dedicated webdav client, i get a valid response and the file is being uploaded. Here is what I get using CyberDuck client:
[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
The CONTENT-LENGTH field changed and the file is online on the server as i should be. I will post my code fragment here:
$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);
}
What could I do to solve this issue? is there any thing to set in Windows to make it work or is it just my code who lacks something?
Windows will first create a 0-byte file. After this succeeds it will upload the entire file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.