php断点续传之文件分割合并详解
php实现断点续传,就需要把大文件分割成多个小文件,然后单个上传。传完后在合并。
│ merge.php C合并文件脚本
│ merge.zip C合并后文件
│ socket.zip C需要分割的文件
│ split.php C分割文件脚本
│
└─split C分割后小文件目录
下面是源码
split.php
<?php $fp = fopen("socket.zip", "rb"); $filesize = 10; $i = 0; $no = 1; while(!feof($fp)) { $file = fread($fp, $filesize); $fp2 = fopen("./split/socket.port".sprintf("%04d",$no).".".$i."-".($i+$filesize).".tmp", "wb"); fwrite($fp2, $file, $filesize); fclose($fp2); $i+=$filesize+1; $no++; } fclose($fp);
merge.php
<?php $filelist = glob('./split/*socket*.tmp'); $filesize = 10; //print_r($filelist); $mergeFileName = 'merg.zip'; unlink($mergeFileName); $fp2 = fopen($mergeFileName,"w+"); foreach($filelist as $k => $v) { $fp = fopen($v, "rb"); $content = fread($fp, $filesize); fwrite($fp2, $content, $filesize); unset($content); fclose($fp); echo $k,"\n"; } fclose($fp2);
相关推荐
mathchao 2020-10-28
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23