http://www.resumablejs.com/ 官网
upload.html
<!DOCTYPE html>
<html lang="en"> <div>
<a href="#" id="browseButton" >Select files</a>
<div>
<div>
<input id="btnCancel" type="button" onClick='r.pause()'value="Cancel All Uploads"
style="margin-left: 2px; height: 22px; font-size: 8pt;" />
<br />
</div>
<script src="resumable.js"></script>
<script>
var r = new Resumable({
target:'upload.php',
chunkSize:**,
simultaneousUploads:,
testChunks:true,
throttleProgressCallbacks:, }); r.assignBrowse(document.getElementById('browseButton')); r.on('fileSuccess', function(file){
// console.debug(file);
});
r.on('fileProgress', function(file){
// console.debug(file);
});
r.on('fileAdded', function(file, event){
r.upload();
//console.debug(file, event);
});
r.on('fileRetry', function(file){
//console.debug(file);
});
r.on('fileError', function(file, message){
//console.debug(file, message);
});
r.on('uploadStart', function(){
//console.debug();
});
r.on('complete', function(){
//console.debug();
});
r.on('progress', function(){
//console.debug();
});
r.on('error', function(message, file){
//console.debug(message, file);
});
r.on('pause', function(file,message){
//console.debug(); });
r.on('cancel', function(){
//console.debug();
});
</script> </html> upload.php
<?php
/**
* This is the implementation of the server side part of
* Resumable.js client script, which sends/uploads files
* to a server in several chunks.
*
* The script receives the files in a standard way as if
* the files were uploaded using standard HTML form (multipart).
*
* This PHP script stores all the chunks of a file in a temporary
* directory (`temp`) with the extension `_part<#ChunkN>`. Once all
* the parts have been uploaded, a final destination file is
* being created from all the stored parts (appending one by one).
*
* @author Gregory Chris (http://online-php.com)
* @email www.online.php@gmail.com
*/ ////////////////////////////////////////////////////////////////////
// THE FUNCTIONS
//////////////////////////////////////////////////////////////////// /**
*
* Logging operation - to a file (upload_log.txt) and to the stdout
* @param string $str - the logging string
*/
function _log($str) { // log to the output
$log_str = date('d.m.Y').": {$str}\r\n";
echo $log_str; // log to file
if (($fp = fopen('upload_log.txt', 'a+')) !== false) {
fputs($fp, $log_str);
fclose($fp);
}
} /**
*
* Delete a directory RECURSIVELY
* @param string $dir - directory path
* @link http://php.net/manual/en/function.rmdir.php
*/
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") {
rrmdir($dir . "/" . $object);
} else {
unlink($dir . "/" . $object);
}
}
}
reset($objects);
rmdir($dir);
}
} /**
*
* Check if all the parts exist, and
* gather all the parts of the file together
* @param string $dir - the temporary directory holding all the parts of the file
* @param string $fileName - the original file name
* @param string $chunkSize - each chunk size (in bytes)
* @param string $totalSize - original file size (in bytes)
*/
function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize) { // count all the parts of this file
$total_files = ;
foreach(scandir($temp_dir) as $file) {
if (stripos($file, $fileName) !== false) {
$total_files++;
}
} // check that all the parts are present
// the size of the last part is between chunkSize and 2*$chunkSize
if ($total_files * $chunkSize >= ($totalSize - $chunkSize + )) { // create the final destination file
if (($fp = fopen('temp/'.$fileName, 'w')) !== false) {
for ($i=; $i<=$total_files; $i++) {
fwrite($fp, file_get_contents($temp_dir.'/'.$fileName.'.part'.$i));
_log('writing chunk '.$i);
}
fclose($fp);
} else {
_log('cannot create the destination file');
return false;
} // rename the temporary directory (to avoid access from other
// concurrent chunks uploads) and than delete it
if (rename($temp_dir, $temp_dir.'_UNUSED')) {
rrmdir($temp_dir.'_UNUSED');
} else {
rrmdir($temp_dir);
}
} } ////////////////////////////////////////////////////////////////////
// THE SCRIPT
//////////////////////////////////////////////////////////////////// //check if request is GET and the requested chunk exists or not. this makes testChunks work
if ($_SERVER['REQUEST_METHOD'] === 'GET') { $temp_dir = 'temp/'.$_GET['resumableIdentifier'];
$chunk_file = $temp_dir.'/'.$_GET['resumableFilename'].'.part'.$_GET['resumableChunkNumber'];
if (file_exists($chunk_file)) {
header("HTTP/1.0 200 Ok");
} else
{
header("HTTP/1.0 404 Not Found");
}
} // loop through files and move the chunks to a temporarily created directory
if (!empty($_FILES)) foreach ($_FILES as $file) { // check the error status
if ($file['error'] != ) {
_log('error '.$file['error'].' in file '.$_POST['resumableFilename']);
continue;
} // init the destination file (format <filename.ext>.part<#chunk>
// the file is stored in a temporary directory
$temp_dir = 'temp/'.$_POST['resumableIdentifier'];
$dest_file = $temp_dir.'/'.$_POST['resumableFilename'].'.part'.$_POST['resumableChunkNumber']; // create the temporary directory
if (!is_dir($temp_dir)) {
mkdir($temp_dir, , true);
} // move the temporary file
if (!move_uploaded_file($file['tmp_name'], $dest_file)) {
_log('Error saving (move_uploaded_file) chunk '.$_POST['resumableChunkNumber'].' for file '.$_POST['resumableFilename']);
} else { // check if all the parts present, and create the final destination file
createFileFromChunks($temp_dir, $_POST['resumableFilename'],
$_POST['resumableChunkSize'], $_POST['resumableTotalSize']);
}
}

resumablejs 分块上传 断点续传的更多相关文章

  1. php大文件分块上传断点续传demo

    前段时间做视频上传业务,通过网页上传视频到服务器. 视频大小 小则几十M,大则 1G+,以一般的HTTP请求发送数据的方式的话,会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长, ...

  2. web大文件分块上传断点续传demo

    一.概述 所谓断点续传,其实只是指下载,也就是要从文件已经下载的地方开始继续下载.在以前版本的HTTP协议是不支持断点的,HTTP/1.1开始就支持了.一般断点下载时才用到Range和Content- ...

  3. asp.net大文件分块上传断点续传demo

    IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...

  4. .net大文件分块上传断点续传demo

    IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...

  5. js大文件分块上传断点续传demo

    文件夹上传:从前端到后端 文件上传是 Web 开发肯定会碰到的问题,而文件夹上传则更加难缠.网上关于文件夹上传的资料多集中在前端,缺少对于后端的关注,然后讲某个后端框架文件上传的文章又不会涉及文件夹. ...

  6. java大文件分块上传断点续传demo

    第一点:Java代码实现文件上传 FormFile file = manform.getFile(); String newfileName = null; String newpathname =  ...

  7. 前端js怎么实现大文件G级的断点续传(分块上传)和分段下载

    需求: 支持大文件批量上传(20G)和下载,同时需要保证上传期间用户电脑不出现卡死等体验: 内网百兆网络上传速度为12MB/S 服务器内存占用低 支持文件夹上传,文件夹中的文件数量达到1万个以上,且包 ...

  8. Asp.net mvc 大文件上传 断点续传

    Asp.net mvc 大文件上传 断点续传 进度条   概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这 ...

  9. Asp.net mvc 大文件上传 断点续传 进度条

    概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这篇文章,此方法确实很不错,能够稳定的上传大文件,http: ...

随机推荐

  1. django中使用Profile扩展User模块(基于django 1.10版本下)

    版本:Django 1.10.1(其他版本可能有不同的实现好解决办法) 参考官方文档:https://docs.djangoproject.com/en/1.10/topics/auth/custom ...

  2. [学习笔记]坚果云网盘,SVN异地代码管理

    SVN的好处不必多说了.但是如果希望有一份自己的用来学习和储备的代码仓库,那么能够异地同步是必不可少的了. 参考作者Mike_QSJ的文章,但是实际上做了很大的改动.一方面使用更常见的windows系 ...

  3. 使用spring的特殊bean完成配置

    1.分散配置 beans.xml配置如下: 使用占位符变量代替bean装配文件中的硬编码配置.占位符采用${variable}形式. 说明:当通过context:property-placeholde ...

  4. netload 加载程序集抛异常----无法加载程序集解决办法

    netload 加载程序集抛异常----无法加载程序集 错误信息如下: 无法加载程序集.错误详细信息: System.BadImageFormatException: 未能加载文件或程序集“file: ...

  5. .net core Entity Framework Core Code First 框架 分层开发

    由于之前苦于无法把 Entityframework 跟Web层剥离.找了很久..找到了这个框架..分享给大家..  GitHub 地址:https://github.com/chsakell/dotn ...

  6. text-align:justify的使用

    在平常的开发过程中,对于text-align一般用到的是left,center,right,这三个属性都不会陌生.然而,对于justify的使用我却是很陌生.首先有个比较简单的例子. 首先是html代 ...

  7. Java 第29章GUI

    GUI入门 JDBC 连接数据库的过程 注册驱动(class ,forName) 创建连接 创建连接对象 执行SQL语句 statement对象的类型与作用 1.(layout :版面,布局) 2.( ...

  8. VS2013 密钥 – 所有版本(Visual Studio Ultimate,Premium,Professional,TFS)

    Visual Studio Ultimate 2013 KEY(密钥):BWG7X-J98B3-W34RT-33B3R-JVYW9 Visual Studio Premium 2013 KEY(密钥) ...

  9. 使用IConfigurationSectionHandler在web.config中增加自定义配置

    一. 场景    这里仅举一个简单应用的例子,我希望在web.config里面增加网站的基本信息,如:网站名称,网站版本号,是否将网站暂时关闭等.二. 基本实现方法1. 定义配置节点对应的类:Site ...

  10. springmvc No mapping found for HTTP request with URI in Dispatc

    springmvc No mapping found for HTTP request with URI in Dispatc 博客分类: Java Web springmvcspring MVCNo ...