js code
[html]
view plain
copy

- >
- <html>
- <head>
-
title>
head- > <body> <
- div id="drop_area"
- style="border: 3px dashed silver;width:200px; height:200px" >
- Drag the image here div> value="0" max
=- "10"
- id="prouploadfile">
progress- >
- ent">0%span > <button onclick
=- "stopup()"
- id="stop" >Upload button> /Drag and drop upload starts . " }) There not worse not No matter more in the other’s being’ themselves — (e){ //Drag and drop )
- document.addeventListener ("Dragenter", function (e) {// Drags
- e.preventdeFault ();
- })
- docume {
- var pro
= - document
. getElementById('prouploadfile'); function clearpro(){ - pro.value =0;
- var stopbutton = document.getElementById('stop');
-
var box
- = document.getElementById('drop_area'); //Drag area box.addEventListener("drop",function(e){
- var fileList = e.dataTransfer.files; //Get the file object
- console.log(fileList)
- //Detect whether the file is dragged to the page .length
== 0){ 到 // Drag the picture to the browser, you can realize the preview function - // Standardized video format
- // in_array
-
Array.prototype.s
- = String .fromCharCode(2); var r
- =new RegExp(this.S +e+this.S); var video_type=["video/mp4","video/ogg"];
-
var fileurl = window.URL.createObjectURL(fileList[0]); var str
- ="
>
- "; document.getElementById('drop_area ').innerHTML
- =str
- ; ’s video str
=-
">
- "; T document.GetelementByid ('Drop_area') .innerhtml
= - str; } else {// Other formats, output file names // alert ("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Alert ("" "" " No preview");
- var str="File name: "+fileList[0].name;
- document.getElementById('drop_area').innerHTML
=- str; }
- = resultfile.size;
-
file //console.log(filecount)
-
;
- i):0 . .value=i+1;
- alert (i); =parseInt
- (i)*100/Math.ceil(filecount) ,false);
-
-
=
- 1;
-
O if (Stopf == 1) { Return false;
-
}
- if (ResultFile == "") {
-
Alert ("" Please select a file")
-
- getCookie(resultfile.name);
If(Math.floor(filecount)- <parseInt
- (i)){
- alert("Completed");
- return false;
- var formData = new
- FormData(); //++++++++++
- i+1;
-
- ? parseInt
(p)+"%"; - //Progress bar resultfile
.slice(i*setsize,filesize);formData.append('blobname', i); //++++++++++ + - formData.append('filename', resultfile.name); //++++++++++ formData.append('filename', resultfile.name); //++++++++++ xhr.open('POST', 'xhr2.php'); //The second step
- stopbutton.innerHTML
- = " Pause "
-
-
(){ //Step 4 - == 4 && xhr.status
- == 200 ) {
- console.log(xhr.responseText); If(i<filecount){
/Set timeout - xhr.ontimeout = function(event){
Request timed out, network congestion!低于25K/s'); - }
-
- i=i+1;
- setCookie(resultfile.name,i,365)
-
- }
-
- //设置cookie
- function setCookie(c_name,value,expiredays)
- {
- var exdate=new Date()
- exdate.setDate(exdate.getDate()+expiredays)
- document.cookie=c_name+ "=" +escape(value)+
- ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/")
- }
- //获取cookie
- function getCookie(c_name)
- {
- if (document.cookie.length>0)
- {
- c_start=document.cookie.indexOf(c_name + "=")
- if (c_start!=-1)
- {
- c_start=c_start + c_name.length+1
- c_end=document.cookie.indexOf(";",c_start)
- if (c_end==-1) c_end=document.cookie.length
- return unescape(document.cookie.substring(c_start,c_end))
- }
- }
- return ""
- }
-
-
- function stopup(){
- if(stop==1){
- stop = 0
-
- xhr2();
- }else{
- stop = 1
- stopbutton.innerHTML = "继续"
-
- }
-
- }
- script>
- body>
- html>
php代码
[php]
view plain
copy

- //$name=$_POST['username'];
- $dir=$_POST['filename'];
- $dir="uploads/".md5($dir);
- file_exists($dir) or mkdir($dir,0777,true);
-
-
- $path=$dir."/".$_POST['blobname'];
-
-
- //print_r($_FILES["file"]);
- move_uploaded_file($_FILES["file"]["tmp_name"],$path);
-
- if(isset($_POST['lastone'])){
- echo $_POST['lastone'];
- $count=$_POST['lastone'];
-
- $fp = fopen($_POST['filename'],"abw");
- for($i=0;$i<=$count;$i++){
- $handle = fopen($dir."/".$i,"rb");
- fwrite($fp,fread($handle,filesize($dir."/".$i)));
- fclose($handle);
- }
- fclose($fp);
- }
-
-
- ?>
以上就介绍了 html5解决大文件断点续传,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。