2

I'm a student, new to PHP (and web development in general), and am trying to write a simple interface with my college's WebDAV server.

The following code (with appropriate credentials and address), which uses an HTTP WebDAV Client plugin I found (https://github.com/pear/HTTP_WebDAV_Client), successfully returns the first 8k of data from the .txt/.html/.js files I've tried it with, but no more.

From what I can tell, the likely culprit is that the server is using chunked transfer encoding (which makes sense), which leads me to believe I will have to read in a stream of data, rather than a single file/chunk (again, I'm new to this). If so, I'm not certain of how to accomplish this.

My understanding is that cURL would likely be the fastest way to do this, but I don't think Dreamhost has cURL enabled for php.

//this loads the HTTP_WebDAV_Client plugin:
//  https://github.com/pear/HTTP_WebDAV_Client
require_once "HTTP/WebDAV/Client.php";

    //this is for testing purposes only (for obvious reasons)
    $user = $_GET['user'];
    $pass = $_GET['pass'];
    $fileName = $_GET['fileName'];

    //actual address obscured
    $dir = "webdavs://" . $user . ":" . $pass . "@webfs.xxx.com/main/hcwebdav/";

    $file = fopen($dir.$fileName, "rb");
    //$content;

    if (!$file) {

        die("Error opening file :( $user $pass");

    } else {
        //This returns only the first chunk:
        echo file_get_contents($dir.$fileName);

        //this has the same behavior
        /*
        while ($line = fread($file, 8192)) {
            $content .= $line;
        }
        echo $content;

        fclose($file);
        */

    }

I hope this question isn't too stupid :/ I'm trying to write web applications to help intro-level students learn to code, and this plug-in would make it very easy for them to publish their own websites from a browser-based code editor/mini-IDE!

Cheers!

  • http://php.net/manual/en/ref.stream.php – adeneo Mar 28 '15 at 20:43
  • @adeneo - Should I assume the answer to my question is that standard file operations won't work on chunked streams? I was so excited to have it (mostly) working with simple fopen()/fread() commands, I guess I hadn't considered going an entirely different route. – Steve Henningsgard Mar 28 '15 at 20:50

1 Answers1

2

My suggestions leads away from the package you are using and your issue with it, but SabreDAV is the most popular WebDAV in the PHP community, so why not using it instead.

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141