大文件(視頻)上傳

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>視頻上傳</title>
 6 </head>
 7 <body>
 8 <input type="file" id="mp4">
 9 </body>
10 </html>
11 <script>
12     var start,end,len,file,num,bolb;
13     document.getElementById("mp4").onchange=function () {
14         num = 1;
15         start = 0;
16         len = 1024*1024;
17         end = start+len;
18         file = this.files[0];
19         console.log(file);
20         bolb = cutFile();
21         console.log(bolb);
22         sendFile();
23     }
24     function cutFile(){
25         bolb = file.slice(start,end);
26         start = end;
27         end = start+len;
28         return bolb;
29     }
30     function sendFile(){
31         var obj = new FormData();
32         obj.append('bolb',bolb);
33         obj.append('num',num);
34         obj.append('name',file.name);
35         obj.append('counts',Math.ceil(file.size/len));
36         var xhr = new XMLHttpRequest();
37         xhr.open("post","loud.php",true);
38         xhr.send(obj);
39         if (start<file.size){
40             var t = setTimeout(function () {
41                 num++;
42                 cutFile();
43                 sendFile();
44             },1000)
45         } else {
46             clearTimeout(t);
47         }
48     }
49 </script>
 1 <?php
 2 $num = $_POST['num'];
 3 $tmpname = $_FILES['bolb']['tmp_name'];
 4 move_uploaded_file($tmpname,"zhao-".$num);
 5 if ($num==$_POST['counts']){
 6     $str = "";
 7     for ($i=1;$i<=$_POST['counts'];$i++){
 8         $str .=file_get_contents("zhao-".$i);
 9     }
10     file_put_contents("zhaona.mp4",$str);
11 }
原文地址:https://www.cnblogs.com/songbao/p/11226312.html