";file_get_contents()";仅返回第一个区块(WebDAV)


"file_get_contents()" returns only the first chunk (WebDAV)

我是一名学生,刚接触PHP(以及一般的web开发),正试图用我所在大学的WebDAV服务器编写一个简单的界面。

下面的代码(带有适当的凭据和地址),它使用了我找到的HTTPWebDAV客户端插件(https://github.com/pear/HTTP_WebDAV_Client),成功地返回了我尝试过的.txt/.html/.js文件中的前8k数据,但没有更多。

据我所知,可能的罪魁祸首是服务器使用了分块传输编码(这是有道理的),这让我相信我必须读取数据流,而不是单个文件/块(再说一次,我是新手)。如果是这样的话,我不确定如何做到这一点。

我的理解是cURL可能是最快的方法,但我认为Dreamhost没有为php启用cURL。

//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);
        */
    }

我希望这个问题不要太愚蠢:/我正在尝试编写网络应用程序来帮助入门级学生学习编码,这个插件将使他们可以很容易地从基于浏览器的代码编辑器/迷你IDE发布自己的网站!

干杯!

我的建议不涉及您正在使用的包和您的问题,但SabreDAV是PHP社区中最受欢迎的WebDAV,为什么不使用它呢。

  • http://sabre.io/
  • https://github.com/fruux/sabre-dav
  • Docu:http://sabre.io/dav/davclient/