【发布时间】:2015-03-28 20:39:53
【问题描述】:
我是一名学生,刚接触 PHP(以及一般的 Web 开发),我正在尝试用我大学的 WebDAV 服务器编写一个简单的界面。
以下代码(具有适当的凭据和地址)使用我找到的 HTTP WebDAV 客户端插件 (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);
*/
}
我希望这个问题不会太愚蠢:/ 我正在尝试编写 Web 应用程序来帮助初级学生学习编码,而这个插件可以让他们很容易地发布自己的网站基于浏览器的代码编辑器/迷你IDE!
干杯!
【问题讨论】:
-
@adeneo - 我是否应该假设我的问题的答案是标准文件操作不适用于分块流?我很高兴它(主要)使用简单的 fopen()/fread() 命令,我想我没有考虑过完全不同的路线。
标签: php webdav chunked-encoding