<?php$fileTotaiSize = filesize("socket.zip");$filelist = glob('./split/*socket*.tmp');$filesize = 3096;//打乱读取文件顺序shuffle($filelist);$mergeFileName = 'merg2.zip'; if(is_file($mergeFileName)) { unlink($mergeFileName); } $fp2 = fopen($mergeFileName,"w+"); //创建空白文件 $str = str_pad('',$fileTotaiSize); fwrite($fp2, $str, $fileTotaiSize);foreach($filelist as $k => $v){ $tmp = explode('.',$v); $len = explode('-', $tmp[3]); $offset = (int) $len[0]; $fp = fopen($v, "rb"); $content = fread($fp, $filesize); echo $offset, "/n"; fseek($fp2, $offset); fwrite($fp2, $content, strlen($content)); unset($content); fclose($fp);}fclose($fp2);
<?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);