你好 PHP 世界 经过几个小时的担心 :=)
我找到了恢复或暂停上传的解决方案
在此代码片段中,它是服务器端,而不是任何桌面程序上的客户端,您必须使用字节范围来计算已上传的字节和总字节数的缺失部分。
以下是 PHP 代码
<?php
$CHUNK = 8192;
try {
if (!($putData = fopen("php://input", "r")))
throw new Exception("无法获取PUT数据。");
$tot_write = 0;
$tmpFileName = "/var/dev/tmp/PUT_FILE";
if (!is_file($tmpFileName)) {
fclose(fopen($tmpFileName, "x")); if (!($fp = fopen($tmpFileName, "w")))
throw new Exception("无法写入临时文件。");
while ($data = fread($putData, $CHUNK)) {
$chunk_read = strlen($data);
if (($block_write = fwrite($fp, $data)) != $chunk_read)
throw new Exception("无法继续写入临时文件。");
$tot_write += $block_write;
}
if (!fclose($fp))
throw new Exception("无法关闭临时文件。");
unset($putData);
} else {
if (!($fp = fopen($tmpFileName, "a")))
throw new Exception("无法写入临时文件。");
while ($data = fread($putData, $CHUNK)) {
$chunk_read = strlen($data);
if (($block_write = fwrite($fp, $data)) != $chunk_read)
throw new Exception("无法继续写入临时文件。");
$tot_write += $block_write;
}
if (!fclose($fp))
throw new Exception("无法关闭临时文件。");
unset($putData);
}
if ($tot_write != $file_size)
throw new Exception("文件大小错误。");
$md5_arr = explode(' ', exec("md5sum $tmpFileName"));
$md5 = $md5sum_arr[0];
if ($md5 != $md5sum)
throw new Exception("MD5错误。");
} catch (Exception $e) {
echo '', $e->getMessage(), "\n";
}
?>