這篇文章主要為大家詳細介紹了php斷點續傳之文件分割合併,具有一定的參考價值,有興趣的小夥伴們可以參考一下
php實現斷點續傳,就需要把大文件分割成多個小文件,然後單一上傳。傳完後在合併。
│ merge.php –合併檔案腳本
│ merge.zip –合併後檔案
│ socket.zip –需要分割的檔案
│ split.php –分割檔案腳本
│
└─split –分割後小檔案目錄
#下面是原始碼
##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);
以上是php斷點續傳之文件分割合併實例詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!