上傳大檔案 關於大檔案上傳

2021-10-16 02:53:24 字數 1479 閱讀 5173

js計算檔案md5使用spark-md5.js,據說這個庫使用的是世界上最快的md5演算法。

js對檔案切片並使用ajax上傳切片:

//...

let size = file.size; //獲取檔案大小

const shardsize = 1024 * 1024; // 塊大小1mb

let shardcount = math.ceil(size/shardsize); //可切成的塊數

for(let i = 0; i < shardcount; i++)

}}

php端儲存切片

$path = __dir__ . '/uploads';

$file = $_files['file'];

$total = $_post['total'];

$index = $_post['index'];

$size = $_post['size'];

$dst_file = $path . '/' . $name . '-' . $total . ':' . $index; // 切片檔案儲存的檔名

if ($file["error"] > 0) else else

}

php端合併

//...

function mergefile($name, $total, &$msg)

else if (filesize($name . '-' . $total . ':' . $i) != file_get_contents($name . '-' . $total . ':' . $i . '.info'))

}@unlink($name);

if (file_exists($name . '.lock'))

touch($name . '.lock');

$file = fopen($name, 'a+');

for ($i = 0; $i < $total; $i++)

fclose($file);

unlink($name . '.lock');

return true;

}

我也寫好了乙個demo,傳送門

下面是這個demo的效果圖:

這個demo有些方面還不夠完善,後續持續完善吧~

原文連線:

關於大檔案上傳​www.ioio.pw

大檔案上傳

首先先要建好幾個檔案 html裡面 1238 9141589 90php裡面 1 2 username post username 3 1 接收前端傳過來的引數 4 ori file name post filename 原始檔案的檔名 5 file files file 6 tmp name fi...

大檔案上傳

大檔案上傳 服務端import socket import os import json import struct server socket.socket server.bind 127.0.0.1 8080 server.listen 5 while true conn,addr server...

大檔案上傳

html頁面 td 姓名 td td input type text name uname class uname placeholder 姓名 td tr tr td 年齡 td td input type text name age class age placeholder 年齡 td tr ...